Here is a simple puzzle that disappointed me today:
Consider this page layout:
<head> <style type="text/css"> #wrapper { overflow: hidden; } #content { width: 750px; height: 100px; background: orange; } </style> </head> <body> <div id="wrapper"> <div id="content">Foo bar</div> </div> </body>
How can I get div#content in the center of the page regardless of the width of the viewport?
I tried various tricks (including text-align: center; display: inline-block; ) and absolute positioning, but with all of them div#content is left-aligned when the browser window is 750 pixels wide.
I have seen several famous sites in the past. For example, on Apple.com, when they advertised a new retina for the iPad: the iPad had a very wide image that extended past the area of ββthe main page (note that this is not a background image of the CSS element <body> ), but it doesnβt cause scrolling when the browser window matches only the contents of the main page.Unfortunately, I can not find any existing sites that do this, so I can not find the link.
Thanks.
source share