onjegolders
onjegolders

Reputation: 1059

Centering container for 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

Upvotes: 3

Views: 5324

Answers (2)

mloffland
mloffland

Reputation: 11

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

div #container {
  display: inline-block;
}

Upvotes: 1

MatTheCat
MatTheCat

Reputation: 18721

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.

Upvotes: 1

Related Questions