i have div which contains all page content including header footer etc.
So i would like to center this div to t
One way is to create a wrapper around your #page
element, let's call it #wrapper
:
#wrapper {
position: relative;
left: 50%;
float: left;
}
#page {
position: relative;
left: -50%;
float: left;
}
This will allow the #page
div to remain a variable width.
See: http://jsfiddle.net/thirtydot/rjY7F/
HTML:
<div id="container">
i'm as wide as my content
</div>
CSS:
body {
text-align: center;
}
#container {
text-align: left;
border: 1px solid red;
display: inline-block;
/* for ie6/7: */
*display: inline;
zoom: 1;
}
how about this?
body {
text-align: center;
}
#container {
text-align: left;
}
Assuming <body><div id="container"></div></body>
This will give you a dinamically-sized div that stays at the center of the body and is the smallest size needed to fit the content:
body { text-align: center; }
div.container { display: inline-block; text-align: left; }