<html>
<body>
<style type="text/css">
p.first {color:blue}
p.second {color:green}
</style>
<p class="first">Hello World</p>
<p class="second">Hello World</p>
<style type="text/css">
p.first {color:green}
p.second {color:blue}
</style>
<p class="first">Hello World</p>
<p class="second">Hello World</p>
</body>
</html>
一个浏览器应该如何渲染css是不连续的?它是否应该生成一些数据结构,使用页面上所有的css样式,并使用它进行渲染?
还是按照看到的顺序使用样式信息进行渲染?
当我看到大型站点的内容管理系统经常将一些<style>元素(一些,而不是全部)放置在依赖于这些类的内容附近时,我就得出结论说,情况已经不一样了。
去看看cnn.com, nytimes.com, huffingtonpost.com,你最近的大城市报纸,等等。他们都这样做。
If there's a good reason to put an extra <style> section somewhere in the body -- for instance if you're include()ing diverse and independent page elements in real time and each has an embedded <style> of its own, and the organization will be cleaner, more modular, more understandable, and more maintainable -- I say just bite the bullet. Sure it would be better if we could have "local" style with restricted scope, like local variables, but you go to work with the HTML you have, not the HTML you might want or wish to have at a later time.
当然,正如其他人所阐述的那样,遵循正统有潜在的缺点和好的(如果不总是令人信服的)理由。但在我看来,<style>在<body>中经过深思熟虑的使用已经越来越成为主流。
当我看到大型站点的内容管理系统经常将一些<style>元素(一些,而不是全部)放置在依赖于这些类的内容附近时,我就得出结论说,情况已经不一样了。
去看看cnn.com, nytimes.com, huffingtonpost.com,你最近的大城市报纸,等等。他们都这样做。
If there's a good reason to put an extra <style> section somewhere in the body -- for instance if you're include()ing diverse and independent page elements in real time and each has an embedded <style> of its own, and the organization will be cleaner, more modular, more understandable, and more maintainable -- I say just bite the bullet. Sure it would be better if we could have "local" style with restricted scope, like local variables, but you go to work with the HTML you have, not the HTML you might want or wish to have at a later time.
当然,正如其他人所阐述的那样,遵循正统有潜在的缺点和好的(如果不总是令人信服的)理由。但在我看来,<style>在<body>中经过深思熟虑的使用已经越来越成为主流。