代码:
<!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>
/* li:first-child{
background-color: darkgrey;
}
表示给第一个孩子标签加上样式
li:not(:first-child){
background-color: darkgrey;
}
表示除了第一个孩子标签以外的都加上样式
li:nth-child(2n+1){
background-color: aqua;
}
表示给奇数的li标签加上背景颜色
li:not(:nth-child(2n+1)){
background-color: aqua;
}
加上:not()就变成了偶数的li加上背景色
*/
div{
width: 100px;
height: 100px;
}
/* div:empty{
background-color: yellowgreen;
}
表示给空的div加上背景色 */
div:not(:empty){
background-color: yellowgreen;
}
/* 表示把非空的div加上背景 */
</style>
</head>
<body>
<ul>
<li>111</li>
<li>222</li>
<li>333</li>
<li>444</li>
<li>555</li>
<li>666</li>
</ul>
<div></div>
<div>777</div>
</body>
</html>