第一个孩子的选择

杜哈内斯

在本练习中,我很好奇要学习第一个孩子选择器的工作原理。例如,尝试选择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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章