在本练习中,我很好奇要学习第一个孩子选择器的工作原理。例如,尝试选择h1
标签并为其赋予颜色。
.col1:first-child {
color: green;
}
<div class="col1">
<h1> This is something awesome!</h1>
<p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorlike).</p>
<button type="button" class="button">Click Me!</button>
</div>
注意:该问题仅与第一个孩子及其实际工作方式有关,因为我认为theh1
是div col1的第一个孩子,但没有任何作用。
.col1:first-child
表示“其中的一个成员col1
是其父项的第一个孩子”,而不是“每个元素的第一个子项是”的成员col1
。
为此,您需要插入一个子组合器:
.col1 > :first-child {}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句