【发布时间】:2016-02-02 03:47:11
【问题描述】:
我正在使用以下定义(改编自 CSS2 规范 http://www.w3.org/TR/CSS21/cascade.html#specificity)
- a = 使用样式属性 元素
- b = id 属性数
- c = 属性(类)和伪类(:link, :hover)的数量
- d = 元素和伪元素的数量(:first-line, :first-letter)
使用以下样式(我的计算在右边):
.content {color: green;} /* a=0 b=0 c=1 d=0 -> 0,0,1,0 */
.content:hover {color: yellow;} /* a=0 b=0 c=2 d=0 -> 0,0,2,0 */
li {color: orange;} /* a=0 b=0 c=0 d=1 -> 0,0,0,1 */
li:first-line {color: pink;} /* a=0 b=0 c=0 d=2 -> 0,0,0,2 */
和下面的html
<li class="content">The first line</li>
当我在浏览器中打开它时,文本行是粉红色的。我以为它会是绿色的,悬停时会是黄色的。我认为元素和伪元素(计算中的 d)的权重低于类和伪类(计算中的 c)。
【问题讨论】:
标签: css