0
点赞
收藏
分享

微信扫一扫

一分钟讲清关于:nth-child(n)和nth-of-type(n)区别

才德的女子 2022-03-15 阅读 41
  1. span:nth-child(2):
    选中是第二个孩子而且是span标签;
  2. p:nth-of-type(2)
    将所有孩子中的p标签拎出来,找到第2个。
<!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>
        span:nth-child(2){
            color: red;
        }
        p:nth-of-type(2){
            color: orange;
        }
    </style>
</head>
<body>
    <div>
        <p>我是p标签,我是第一个孩子</p>
        <span>我是span标签</span>
        <p>我是p标签</p>
    </div>
</body>
</html>

在这里插入图片描述

举报

相关推荐

0 条评论