这些CSS定义意味着什么?

时间:2012-12-27 08:24:21

标签: css

我正在浏览的网站有一些看起来像这样的CSS定义:

#intro, #code { ... }
#intro { ... }
#code { ... }

我以前从未见过这个。两个问题:

  1. 在第一种情况下,它是用{定义#intro#code来定义的 相同的初始定义?
  2. #intro#code的后续定义是否与原始内容相加?

4 个答案:

答案 0 :(得分:2)

直接问题的简单答案:

  1. - )

答案 1 :(得分:2)

浏览器从上到下读取每页代码。这意味着,后面的语句会覆盖前者。

在您给出的示例中,这意味着第一个#intro#code获得相同的CSS,之后他们在各自的语句中收到一些额外的CSS。这些单独的语句可以具有相同的属性(例如,width),但最后一个语句将始终是将使用的语句。

#intro, #code {width: 200px;}
#intro {width: 100px;} /* This value overwrites the previous */

异常是指一个语句比另一个语句更具体。例如:

body #wrapper #intro, body #wrapper #intro #code {width: 200px;}
#intro {width: 100px;} /* This value is NOT as specific as or more specific than the previous, so it does NOT overwrite the previous value. */

答案 2 :(得分:1)

是。介绍和代码都是相同的css

#intro { ... }
#code { ... }

他们每个人都有不同的CSS

答案 3 :(得分:1)

#intro, #code { ... } /* selects and styles both */
#intro { ... } /* selects only #intro and styles it */
#code { ... } /* selects only #code and styles it */
#intro #code { ... } /* this means that #code is child of #intro. Selects #code and styles it! */

并且你的两个问题的答案都是

相关问题