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>