Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a wrapper <div> a violation of content-style separation?

Tags:

html

css

It's been said that the goal of CSS is to provide visual presentation and the goal of HTML is to provide structure of the document. Well, thank goodness. It has gotten so much easier, especially compared to font tags!

But in practice, it seems that way many of us still rely on HTML to use CSS when it shouldn't be there. For example, it's common to see a <div id="wrapper"> to wrap around elements inside so the body can be centered. In pure HTML, it would never be used because it's meaningless and it's used ONLY for CSS.

Right? So doesn't using <div id="wrapper"> actually violate one of the fundamentals of content-presentation separation?

like image 515
netrox Avatar asked Oct 19 '10 06:10

netrox


2 Answers

Kind of. But it doesn’t matter.

Principles like “separate content and presentation” are helpful because they help you achieve your goals, by making code easier to change. They’re not like nuclear safety regulations — contradicting them won’t risk anyone dying, so “violation” is a bit of a strong word.

Sticking in a wrapper <div> to work around the limitations in CSS (and/or browsers) is fine. <div> and <span> are intended for that very use, as they're defined to not convey any meaning (i.e. they don't alter the "structure" of the document). It doesn’t hurt the code.

If you can avoid it, great. But don’t worry if you can’t. There are bigger fish to fry.

like image 111
Paul D. Waite Avatar answered Sep 21 '22 18:09

Paul D. Waite


In any case "wrapper" is a bad choice for an id. In general, wrapping DIV's are not used for simple alignment tasks alone (use a SPAN otherwise) and do provide/determine a structure for your web page. Therefore, in my opinion, wrapping DIV's do not violate the content-presentation separation.

like image 35
thomaux Avatar answered Sep 19 '22 18:09

thomaux