Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Centering container for ipad

Tags:

css

ipad

am trying to find a way of centering my div #container on the ipad page. It's a fairly simple 960px wide, margin 0 auto job. The body is given a background color but on the ipad either the container just takes up the whole page or the margin works on the left but the page is stuck to the right hand edge.

I've seen various ideas posted over the internet about min-width, viewport etc. Ideally I'd use @media queries in my stylesheet as everything else looks fine by default

Thanks

like image 431
onjegolders Avatar asked Sep 02 '26 13:09

onjegolders


2 Answers

In the box model, total width of an element is the sum of its margin, borders, padding and content width.

Total width of your container is 40 + 960 + 40 = 1040px, while iPad viewport width is 1024px. So you cannot center and you can see unexpected results!

Reduce width or padding of the container to make its total width less than 1024px, width:960px; padding:32px; eg.

like image 122
MatTheCat Avatar answered Sep 05 '26 08:09

MatTheCat


Try changing the DIV's display attribute from the default block to inline-block.

div #container {
  display: inline-block;
}
like image 32
mloffland Avatar answered Sep 05 '26 07:09

mloffland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!