5.结构伪类选择器
html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="css/style01.css">
</head>
<body>
<!--<h3>h3</h3>-->
<p>p1</p>
<p>p2</p>
<p>p3</p >
<ul>
<li>li1</li>
<li>li2</li>
<li>li3</li>
</ul>
</body>
</html>
css:
/*ul的第一个子元素*/
ul li:first-child{
background: #53c48b;
}
/*ul的最后一个子元素*/
ul li:last-child{
background: blue;
}
/*选中p1:
可以通过选中当前p元素的父级元素,选中父级元素的第一个,并且要是当前元素才生效 按照顺序
*/
p:nth-child(1){
background: #451644;
}
/*选中父元素下的p元素的第一个 按照类型*/
p:nth-of-type(2){
background: yellow;
}
运行结果: