是包装< div>违反内容风格分离? [英] Is a wrapper <div> a violation of content-style separation?
问题描述
< div id =wrapper>
来环绕内部的元素,所以正文可以居中。在纯HTML中,它永远不会被使用,因为它没有意义,它只用于CSS。 对吗?所以不使用< div id =wrapper>
实际上违反了内容呈现分离的基本原则之一?
种类。但没关系。
像单独的内容和表示这样的原理很有用,因为它们可以帮助您实现目标,并使代码更易于更改。他们不像核安全法规 - 与他们相互抵触不会冒任何人死亡的危险,所以违规是一个强有力的词。
坚持包装< div>
来解决CSS(和/或浏览器)中的局限性很好。 < div>
和< span>
专门用于这种用途,因为它们被定义为不传达任何含义(即它们不会改变文件的结构)。它不会损害代码。
如果你可以避免它,那很好。但是,如果你不能,不要担心。有更大的鱼要炒。
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?
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.
这篇关于是包装< div>违反内容风格分离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!