Is it useful to #container, #Wrapper in every CSS layout?
Solution 1
Is it useful to add whole code in #container, #Wrapper in every CSS layout?
It would not be needed in every layout unless every layout was the same, and then only if they require a wrapper/container.
Can't we make layout without this extra div ?
Yes, you can sometimes dispense with the extra wrapper div.
What are pros and cons to use this extra div?
It totally depends on your layout. Often with a fixed width centered design, a wrapper makes the most sense. You can also style the body
tag, but then overlays and other elements might look different or not totally fill the screen depending on their implementation.
Is it good practice?
Yes, but only if the layout requires it.
Is it useful for any type of design/layout?
It is normally useful when you need to do a fixed width, centered layout. Not sure of other uses where it is helpful.
Is it semantically correct?
Not really as the body
is really a perfectly good container
or wrapper
so adding another one is redundant. However, it is a necessary evil in many designs depending on browser support needed or the layout that is needed. Go ahead and use it without concern if it makes sense for your project and layout.
Solution 2
Putting a container div around the whole page can be useful in certain situations, e.g. if you want to center everything, you can just put margin: 0 auto;
on the container div and be done. That being said, it is certainly not required nor useful for every type of layout.
As to semantical correctness, sure, having a div
as the only direct child of body
is absolutely okay. A div
tag does not have any semantical meaning in and on itself, the very reason it was introduced was to be able to do layout without misusing semantic tags.
Jitendra Vyas
Hi, I am Jitendra a front-end developer from India specializing in web standards, accessibility, and usability based development.
Updated on June 04, 2022Comments
-
Jitendra Vyas almost 2 years
Is it useful to add whole code in
#container
,#Wrapper
in every CSS layout? Can't we make layout without this extradiv
? What are pros and cons to use this extradiv
?Is it good practice ? Is it useful for any type of design/layout? Is it semantically correct?
-
Jitendra Vyas about 14 yearsi think mainly it's useful for Fixed width , centered websites