css3 nth-last-of-type(n)选择器

  “:nth-last-of-type(n)”选择器和“:nth-of-type(n)”选择器是一样的,

选择父元素中指定的某种子元素类型,但它的起始方向是从最后一个子元素开始,

而且它的使用方法类似于上节中介绍的“:nth-last-child(n)”选择器一样。

示例演示

通过“:nth-last-of-type(n)”选择器将容器“div.wrapper”中的倒数第三个段落背景设置为橙色。

HTML代码:

<div class="wrapper">
  <p>我是第一个段落</p>
  <p>我是第二个段落</p>
  <p>我是第三个段落</p>
  <p>我是第四个段落</p>
  <p>我是第五个段落</p>
  <div>我是一个Div元素</div>
  <p>我是第六个段落</p>
  <p>我是第七个段落</p>
</div>

CSS代码:

.wrapper > p:nth-last-of-type(3){
  background: orange;
}

演示结果:

猜你喜欢

转载自blog.csdn.net/weixin_39093202/article/details/86222429
今日推荐