伪类:条件
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>2021-11-23</title>
</head>
<style type="text/css">
/*避免使用class和id选择器*/
/*ul的第一个子元素*/
ul li:first-child{
background: #0000FF;
}
/*ul的最后一个子元素*/
ul li:last-child{
background: #7CFC00;
}
/*选中p1:定位到父元素选择当前的第一个元素
选中当前p元素的父级元素,选中父级元素的第一个,并且是当前元素才生效
*/
p:nth-child(2){
background: #000000;
}
/*选中父元素下的p元素的第二个,按类型*/
p:nth-of-type(2){
background: #7CFC00;
}
a:hover{
background: #6C6C6C;
}
</style>
<body>
<h1>H1</h1>
<p>p1</p>
<p>p2</p>
<p>p3</p>
<ul>
<li>L4</li>
<li>L5</li>
<li>L6</li>
</ul>
<a href="#">123</a>
</body>
</html>
