虽然这可能会导致一个简单的是或否答案我会去,它反正
请考虑以下示例:
- <html>
- <head>
- </head>
- <body>
- <div class="foo">
- <span class="bar">Hello world!</span>
- <p>Some really interesting text.</p>
- </div>
- </body>
- </html>
CSS
- html {
- /* some css */
- }
- body {
- /* some css */
- }
- div.foo {
- /* some css */
- }
- div.foo span.bar {
- /* some css */
- }
- div.foo p {
- /* some css */
- }
css规则出现的顺序会对浏览器如何(快速)渲染页面有任何影响吗? (在这个例子中,这并不重要,但考虑一个真正的网站,加载了html和css)
所以上述css脚本会比浏览器更快或更容易的呈现:
- div.foo p {
- /* some css */
- }
- div.foo span.bar {
- /* some css */
- }
- div.foo {
- /* some css */
- }
- body {
- /* some css */
- }
- html {
- /* some css */
- }
浏览器是否关心?
我们应该吗?
在询问前阅读:
> Is this how you would structure your CSS stylesheet?
> What’s the best way to organize CSS rules?
> How do browsers read and interpret CSS?