浅谈nth-of-type的运行方式

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .a-list:last-of-type {
        color: red;
      }
      .b-list:first-of-type {
        background: yellow;
      }
    </style>
  </head>
  <body>
    <h1>我是标题</h1>
    <span class="a-list">a0</span>
    <p class="b-list">b0</p>
    <p class="a-list">a1</p>
    <p class="a-list">a2</p>
    <p class="a-list">a3</p>
    <span class="b-list">b1</span>
    <span class="b-list">b2</span>
    <span class="a-list">b3</span>
    <p class="a-list">a4</p>
    <p class="a-list">a5</p>
    <p class="a-list">
      a6
      <span class="b-list">b4</span>
      <span class="a-list">a7</span>
      <span class="b-list">b5</span>
    </p>
    <h4 class="c-list">c1</h4>
    <h4 class="a-list">c2</h4>
    <h4 class="c-list">c3</h4>
  </body>
</html>

在这里插入图片描述
nth-of-type(n)的作用模式是,先找到所有的对应的className,然后从当前className的标签找到所有当前标签元素的兄弟标签元素,然后按照位置先后顺序从1开始排序,看是否为第n个元素,是就加上样式,不是就不变。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值