Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the body wrapping div really necessary?

Tags:

html

css

A popular technique to build a set fixed centered layout is wrap everything in the body in a div and set some CSS rules on it, for example:

<body>
    <div id="wrap">
        all content here
    </div>
</body>

#wrap { width: 850px; margin: 0 auto; }

I was wondering, if there is a reason to add this extra wrapping div, since setting the same CSS rules on the body works. Is it for compatibility with some browsers or just a tradition?

like image 508
stivlo Avatar asked Oct 11 '25 21:10

stivlo


2 Answers

No. You do not need a "wrapper" div that so many use because they saw others do so. Use the body for that as you should. Setting CSS properties on the body was a problem in the past but not any longer.

like image 147
Rob Avatar answered Oct 14 '25 11:10

Rob


It might work in some browsers, I don't think it'll work in all of them. Also, it's quite common to set a background on the body, then a separate one on the wrap.

like image 38
SpoonNZ Avatar answered Oct 14 '25 10:10

SpoonNZ