Emmet和结构伪类

目录

 

一、认识emmet语法​

二、>(子代)和+(兄弟)​

三、*(多个)和^(上一级)​

四、()(分组)​

五、属性(id属性、 class属性、普通属性) {}(内容)​

六、$(数字)​

七、隐式标签​

八、CSS Emmet​

九、结构伪类 - :nth-child​

十、结构伪类 - :nth-last-child( ) ​

十一、结构伪类 - :nth-of-type( )、 :nth-last-of-type( )​

十二、否定伪类(negation pseudo-class)​


 

一、认识emmet语法
0f319482dd7e4938843345220bc3edba.png

二、>(子代)和+(兄弟)
9d5703b3c0a540ad8402bc4440fbff69.png

三、*(多个)和^(上一级)
304d7242d40247ca93f6ae06e62f03fd.png

四、()(分组)
8dd17774dd8a43c6a5d48c8e987957dd.png

五、属性(id属性、 class属性、普通属性) {}(内容)
79dbe5da6c054b858bc9e7768578ba70.png

六、$(数字)
10cc8058ade146e090e85966a87d7c40.png

七、隐式标签
150a56f04ad149caae14787ef0ca591a.png

八、CSS Emmet
224102d4112044e0a4682ce0c36c1506.png

九、结构伪类 - :nth-child
7808e688587e46b5b8200bb65623235e.png

<!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>
    ul li:nth-child(3) {
      color: red;
    }

    /* 0, 1, 2, 3, 4, 5...... */
    ul li:nth-child(2n) {
      color: green;
    }

    ul li:nth-child(2n + 1) {
      color: blue;
    }


    div > div:nth-child(4n + 1) {
      color: orange;
    }

    div > div:nth-child(4n + 2) {
      color: purple;
    }

    div > div:nth-child(4n + 3) {
      color: red;
    }

    div > div:nth-child(4n) {
      color: blue;
    }

    /* 前几个 */
    div > div:nth-child(-n + 5) {
      font-size: 20px;
    }

  </style>
</head>
<body>
  
  <ul>
    <li>列表元素1</li>
    <li>列表元素2</li>
    <li>列表元素3</li>
    <li>列表元素4</li>
    <li>列表元素5</li>
    <li>列表元素6</li>
  </ul>

  <div>
    <div>列表元素1</div>
    <div>列表元素2</div>
    <div>列表元素3</div>
    <div>列表元素4</div>
    <div>列表元素5</div>
    <div>列表元素6</div>
    <div>列表元素7</div>
    <div>列表元素8</div>
    <div>列表元素9</div>
    <div>列表元素10</div>
  </div>

</body>
</html>

27a166adf6b24351b06a2c334c9285c3.png 

十、结构伪类 - :nth-last-child( )
b4fa7ec3a63e43b4887f1eba5a4403a2.png

<!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>
    /* 倒数的某一个时 */
    ul > li:nth-last-child(2) {
      color: red;
    }

    /* 倒数的后几个时 */
    ul > li:nth-last-child(-n + 3) {
      font-size: 20px;
    }
    
  </style>
</head>
<body>
  
  <ul>
    <li>列表元素1</li>
    <li>列表元素2</li>
    <li>列表元素3</li>
    <li>列表元素4</li>
    <li>列表元素5</li>
    <li>列表元素6</li>
    <li>列表元素7</li>
    <li>列表元素8</li>
  </ul>

</body>
</html>

 962002e3edd940599e0fe5bf9f31378e.png

十一、结构伪类 - :nth-of-type( )、 :nth-last-of-type( )
d0d9b221513d47dea1be3595a9b67dd1.png

<!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>
    /* 需求: 选择box中的div元素, 并且是第三个子元素 */
    .box > div:nth-child(3) {
      color: red;
    }

    /* 需求: 选择box中的第三个div元素(排除所有的干扰项) */
    /* 元素:nth-of-type, 只计算符合我元素类型的数量的元素 */
    .box > div:nth-of-type(3) {
      color: blue;
    }
  </style>
</head>
<body>
  
  <div class="box">
    <div>我是列表1</div>
    <p>我是p元素</p>
    <span>我是span1</span>
    <span>我是span2</span>
    <span>我是span3</span>
    <span>我是span4</span>
    <div>我是列表2</div>
    <div>我是列表3</div>
    <div>我是列表4</div>
    <div>我是列表5</div>
    <div>我是列表6</div>
    <div>我是列表7</div>
    <div>我是列表8</div>
    <div>我是列表9</div>
    <div>我是列表10</div>
  </div>

</body>
</html>

dba0349b05f241cb814873030811c8dd.png

<!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>
    .box > :first-child {
      color: red;
    }

    .box > :only-child {
      font-size: 20px;
      font-weight: 700;
    }

    .box > :only-of-type {
      color: purple;
    }

    /* html元素 */
    :root {
      font-size: 30px;
    }

    :empty {
      width: 100px;
      height: 100px;
      background-color: #f00;
    }
  </style>
</head>
<body>
  
  <div class="box">
    <span>我是span元素</span>
    <div>列表内容1</div>
    <div>列表内容2</div>
    <div>列表内容3</div>
    <div>列表内容4</div>
    <div>列表内容5</div>
  </div>


  <div class="box">
    <div>我是box的div</div>
    <span>我是span元素</span>
  </div>

  <div class="box">
    <div>我是box的div</div>
    <div>我是box的div</div>
  </div>

  <div class="container"></div>

</body>
</html>

 72a3f16ea83748348c5981504537ce9d.png

十二、否定伪类(negation pseudo-class)
0bcfa0017c0b4c25968e558dc0beb79b.png

<!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>
    /* .item {
      color: red;
    } */

    .box :not(.why) {
      color: blue;
    }
  </style>
</head>
<body>

  <div class="box">
    <div class="item">列表内容1</div>
    <div class="item">列表内容2</div>
    <div class="why">列表内容3</div>
    <div class="item">列表内容4</div>
    <div class="item">列表内容5</div>
    <div>列表内容5</div>
    <div>列表内容5</div>
    <div>列表内容5</div>
  </div>

</body>
</html>

5211b3ffa83f4b968d6fea52582054ab.png

 

 

 

 

 

 

  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值