maxwelldm Posted September 1, 2010 Report Share Posted September 1, 2010 Very elementary question, which I could not find in the archives. I note that many sites have a wrapper div within which the whole page sits, while others do not. I would have thought that there is an "implicit" page upon which all the content resides, and that the wrapper is redundant, but the fact that it is used by many (but far from all) sites suggests that there must be some reason for it. (It just adds another layer of nesting of divs, presumably a bit more processing) Advice re. benefit/necessity? Quote Link to comment Share on other sites More sharing options...
newseed Posted September 1, 2010 Report Share Posted September 1, 2010 A wrapper div is not required but it is helpful to contain all your other inner html codes. For example, let's say you have 3 divs...a header, content and a footer. You want them to each be 900px wide and centered. The html and css code would look like this: HTML <div id="header"></div> <div id="content"></div> <div id="footer"></div> CSS #header { width: 900px; margin: 0 auto;} #content{ width: 900px; margin: 0 auto;} #footer{ width: 900px; margin: 0 auto;} You will have to apply the necessary css to each of the element to get them to be centered and have a fixed width. Now here's what the code looks like when using a wrapper: HTML <div id="wrapper"> <div id="header"></div> <div id="content"></div> <div id="footer"></div> </div> CSS #wrapper{ width: 900px; margin: 0 auto;} #header { } #content{ } #footer{ } As you can see you use far less css because the header, content and footer divs are block elements which expand the full width of whatever is containing it in which in this case the wrapper is the container. The wrapper then centers all html code contained within it. Quote Link to comment Share on other sites More sharing options...
maxwelldm Posted September 1, 2010 Author Report Share Posted September 1, 2010 Eminently clear and explicit explanation - perfect. I thank you so much. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.