层次选择器
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body p{
background: chartreuse;
}
body>p{
background: fuchsia;
}
.test + p{
background: aqua;
}
.test~p{
background: coral;
}
</style>
</head>
<body>
<p>p0</p>
<P class="test">P1</P>
<P>P2</P>
<P>P3</P>
<ul>
<li>
<p>p4</p>
</li>
<li>
<p>p5</p>
</li>
<li>
<p>p6</p>
</li>
</ul>
<P class="test">P7</P>
<p>p8</p>
</body>
</html>
结构伪类选择器
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
ul li:first-child{
background: coral;
}
ul li:last-child{
background: fuchsia;
}
p:nth-child(1){
background: crimson;
}
p:nth-of-type(2){
background: cornflowerblue;
}
</style>
</head>
<body>
<p>p1</p>
<p>p2</p>
<p>p3</p>
<ul>
<li>li1</li>
<li>li2</li>
<li>li3</li>
</ul>
</body>
</html>
