CSS - Div padding "all except z pixels"
I have a div that needs to stretch the whole way across the page, but the actual content should only be z pixels wide, and centered. That is, the text is not centered, but the area where the content is - the interior of the div, if you will - is centered.
The logical approach is to do something like this:
<div>
<!--I stretch across the entire page!-->
<div>
<!--I am z pixels wide, and my margins are auto. Content goes here.-->
</div>
</div>
The only problem with this is that it seems really div-itis-y. This is something that should be ab开发者_如何学编程le to be achieved using the box model.
Is there anyway to do this without adding divs?
body
already stretches the width of the page, so just use that one interior div
something like
<body>
<div></div>
</body>
and
div{
width:980px;
margin:0 auto;
}
This is what div
s are meant to do.
Now, depending on the content and whether or not you are using HTML5, you may want to wrap it all in another element tag, such as header
, nav
, section
etc.
But there is nothing inherently wrong with using div
s, even nested ones.
精彩评论