css - 内部样式的缩进

标签 css

<分区>

我对下面使用的正确语法感到有点困惑,所以样式元素需要缩进吗?根据 w3schools 的文档,未缩进的版本似乎是正确的,但我被告知对此有矛盾的答案。

<style>
h2 {color:red;}
</style>

<style>
  h2 {color:red;}
</style>

最佳答案

两个缩进都是正确的,这里没有错或对。

但是,第二种方法更具可读性。

我什至会这样写:

<style>
  h2 {
    color: red;
  }
</style>

Louis Lazaris 在 Smashing Magazine 上有一篇不错的文章 Using White Space For Readability In HTML And CSS .您可能想阅读它。但就您的问题而言,CSS 规范中没有对代码缩进的实际限制。

关于css - 内部样式的缩进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33412752/

相关文章:

css - 在 IE 8/9 中显示时我的 css 中的边距/间距异常

jquery - 未捕获的类型错误 : Object [object Object] has no method 'popup'

html - 在 div 内的 div 上使用 "overflow:hidden;"

javascript - jquery 焦点没有第二次触发

jquery - 如何在 Google App Engine 中使用 Google Libraries API (jQuery)?

css - 如何设置 Gtk::ComboBox 的样式

html - SVG 显示 block 导致 IE 11 中元素之间出现间隙

html - 由于未知原因,Rails pre 标签正在插入标签

html - 为什么 GitHub Pages 不将 CSS 应用到其他页面?

css - :first-child with *ngFor is not working properly