使用 :first-child 伪类来选择作为某个元素的第一个子元素。这个特定伪类很容易遭到误解,所以有必要举例来说明。考虑以下标记:

如下:

html:

<div>
<p>These are the necessary steps:</p>
<p>Do <em>not</em> push the brake at the same time as the accelerator.</p>
<div>
<ul>
<li>香蕉</li>
<li>苹果</li>
<li>桃子</li>
</ul>
<ul>
<li>香蕉</li>
<li>苹果</li>
<li>桃子</li>
</ul>
</div>
</div>

CSS:
p:first-child{
color:red;
}

ul:first-child{
color:blue;
}

效果如下:

CSS中:first-child伪类

 

 

 

 

 

相关文章:

  • 2022-12-23
  • 2021-08-28
  • 2022-12-23
  • 2021-08-12
  • 2021-09-19
  • 2021-12-28
  • 2021-12-28
猜你喜欢
  • 2021-10-21
  • 2022-12-23
  • 2022-12-23
  • 2021-12-28
  • 2022-01-30
  • 2021-09-15
  • 2021-11-08
相关资源
相似解决方案