Reputation: 9165
Hello I have a lot of trouble finding a way to center a div in safari on ipad...this works in chrome on ipad but safari doesn't scale in landscape format...the are margins on the left and right but i got to scroll all over the whole thing. Any ideas to make this work in both browsers..chrome and safari?
HTML:
<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
</head>
<body>
<div id="wrapper">
</div>
</body>
</html>
CSS:
#wrapper{
margin: 0 auto;
width:90%;
height:90%;
background-color: black;
}
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
Upvotes: 1
Views: 9186
Reputation: 1452
This is how I would do this. Here is an example
HTML:
<div id="wrapper">
<div class="outer">
<div class="inner">
<div class="content">
</div>
</div>
</div>
</div>
CSS:
#wrapper{
position: absolute;
top:0;
bottom:0;
left:0;
right:0;
}
.outer{
display:table;
table-layout:fixed;
height:100%;
width:100%;
}
.inner{
display:table-cell;
text-align:center;
vertical-align:middle;
width:100%;
position:relative;
}
.content{
width:90%;
height:90%;
background:red;
display:inline-block;
}
Upvotes: 2
Reputation: 16020
If you're defining your width
to be 90%
, you can avoid the issue and simply set margin: 0 5%;
Upvotes: 0