详解:9only-child only-of-type

only-child只有一个子元素的css样式
only-of-type只有一个元素的css样式

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
        .box1 p:only-child/*只有一个儿子的就样式化*/
        {
            color: blue;
        }
        .test1 h2:only-of-type/*意思是*/
        {
            color: red;
        }
    </style>
</head>
<body>
    <div class="box1">
        <p>hello king</p>
    </div>
    <div class="box1">
        <p>hello king</p>
        <p>hello king</p>
    </div>
    <div class="test1">
        <h2>55</h2>
       
    </div>
</body>
</html>
原创文章 107 获赞 14 访问量 1369

猜你喜欢

转载自blog.csdn.net/qq_37805832/article/details/105743674