一、 only-child:当元素是唯一的子元素,被选择
二、only-of-type:当元素是唯一类型的子元素,被选择
<body>
<div class="box">
<div class="box1">我是第一个DIV</div>
<div class="box2">我是第一个DIV</div>
<p>我是唯一的P</p>
</div>
</body>
.box:only-child {
background-color: red;
}
box盒子变为红色,因为box是body下唯一的;
.box1:only-child {
background-color: red;
}
box1盒子不会变为红色,因为box1在box中不是唯一的;
p:only-of-type {
background-color: red;
}
p标签会变为红色,因为p标签是box中唯一的p标签