美文网首页
nth-child 与 nth-of-type的一个细节

nth-child 与 nth-of-type的一个细节

作者: 兮木兮木 | 来源:发表于2021-07-07 09:03 被阅读0次

nth-of-type 选择器只能用在标签后面

nth-child 可以用在类名后面

demo

<!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>
    .container .tt:nth-child(5) {
      /* 这是p4变红 */
      color: red;
    }
    .container p.tt:nth-child(5) {
      /* 这是p4变红 */
      color: red;
    }
    .container p:nth-child(5) {
      /* 这是p4变红 */
      color: red;
    }

    .container p:nth-of-type(2) {
      /* 这是p2变蓝 */
      color: blue;
    }
    .container p.tt:nth-of-type(2) {
      /* 无反应 */
      color: blue;
    }
    .container .tt:nth-of-type(2) {
      /* 无反应 */
      color: blue;
    }
  </style>
</head>
<!-- 
  nth-of-type 选择器只能用在标签后面
  nth-child 可以用在类名后面
 -->
<body>
  <div class="container">
    <span>这是span</span>
    <p>这是p1</p>
    <p>这是p2</p>
    <p class="tt">这是p3</p>
    <p class="tt">这是p4</p>
    <p>这是p5</p>
  </div>
</body>
</html>

相关文章

  • 笔试题整理(十)

    百度 一、辨析nth-child()和nth-of-type() p:nth-child(2)的含义:①该标签是其...

  • nth-child(n)和:nth-of-type(n)的区别

    css中的:nth-child(n)和:nth-of-type(n)的区别

  • nth-child & nth-of-type

    nth-child和nth-of-type区别 上面示例中,nth-child会在B的同级元素节点中寻找符合的元素...

  • nth-child 与 nth-of-type的一个细节

    nth-of-type 选择器只能用在标签后面nth-child 可以用在类名后面 demo

  • css3新特性

    css3: 1、选择器:nth-child()、nth-of-type()、:checked、:disabled ...

  • jquery

    jQuery的API: 1.选择器: > + ~ nth-child(编号),nth-of-type(编号),[...

  • jQuery

    jQuery的API: 1.选择器: > + ~ nth-child(编号),nth-of-type(编号),[属...

  • jquery

    jQuery的API: 1.选择器: > + ~ nth-child(编号),nth-of-type(编号),[属...

  • jquery

    jQuery的API: 1.选择器: > + ~ nth-child(编号),nth-of-type(编号),[属...

  • jquery

    jQuery的API: 1.选择器: > + ~ nth-child(编号),nth-of-type(编号),[属...

网友评论

      本文标题:nth-child 与 nth-of-type的一个细节

      本文链接:https://www.haomeiwen.com/subject/vxcoultx.html