CSS 伪类(Pseudo-classes)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.box {
width: 100px;
height: 100px;
border: 1px solid red;
}
.box:hover {
border-radius: 50%;
background-color: yellow;
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
list-style: none;
}
ul {
width: 520px;
height: auto;
margin: 100px auto;
}
li {
float: left;
width: 70px;
height: 70px;
border: 1px solid #ccc;
text-align: center;
line-height: 70px;
margin-left: -1px;
margin-top: -1px;
}
li:first-child {
background-color: pink;
}
li:last-child {
background-color: pink;
}
li:nth-child(5) {
background-color: pink;
}
li:nth-child(odd) {
background-color: pink;
}
li:nth-child(even) {
background-color: yellow;
}
li:nth-child(n) {
background-color: goldenrod;
}
li:nth-child(2n) {
background-color: purple;
}
li:nth-child(2n+1) {
background-color: red;
}
li:nth-child(-n+5) {
background-color: orange;
}
li:nth-child(5n) {
background-color: royalblue;
}
li:nth-last-child(-n+5) {
background-color: orange;
}
</style>
</head>
<body>
ul>li{$}*35
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
div {
width: 100px;
height: 100px;
margin-top: 20px;
margin-left: 20px;
border: 1px solid green;
}
div:empty {
background-color: yellow;
}
</style>
</head>
<body>
<div></div>
<div>
<span>dzm</span>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
#box:target {
background-color: red;
}
</style>
</head>
<body>
<a href="#box">锚点定位标题</a>
<div id="box">标题</div>
</body>
</html>