Showing posts with label Layout. Show all posts
Showing posts with label Layout. Show all posts

Sunday, February 24, 2008

[CSS Zen Garden]The Negative-Margin Solution for Center layout

#container {
background: #ffc;
position: absolute;
left: 50%;
width: 900px;
margin-left: -450px;
}

margin-left is half of #container width, and position of #container must be absolute.

[CSS Zen Garden]Centered Design Using Auto Margins

The preferred way to horizontally center any element is to use the margin property and set left and right values to auto. For this to work with layouts, you'll create a containing div. You must include a width for your containing div:

div#container {
margin-left: auto;
margin-right: auto;
width: 168px;
}