我使用以下定义(改编自CSS2规范http://www.w3.org/TR/CSS21/cascade.html#specificity)
使用以下样式(我的计算在右侧):
.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 */
Run Code Online (Sandbox Code Playgroud)
和以下的HTML
<li class="content">The first line</li>
Run Code Online (Sandbox Code Playgroud)
当我在浏览器中打开它时,文本行是粉红色的.我以为它会是绿色的,在悬停时,它会是黄色的.我认为元素和伪元素(计算中的d)的重量小于类和伪类(计算中的c).
我想这:first-line比仅仅更具体.content。因此文本的第一行是粉红色的,但列表的项目符号是绿色的(悬停时是黄色的)。一切都很好,对于我来说。
想象一下:first-line选择器只是一个嵌套的文本节点选择器,例如:
<li class="content">
<text:text>The first line</text:text><br />
The second line
</li>
Run Code Online (Sandbox Code Playgroud)
它对嵌套元素进行操作,因此它比任何其他选择器都更重要。
| 归档时间: |
|
| 查看次数: |
482 次 |
| 最近记录: |