名称 | 用法 |
---|---|
结构伪类 | li:nth-of-type();p:nth-child() |
状态伪类 | input:disabled |
链接伪类 | a:link;a:hover |
<!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>伪类选择器</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<ul>
<li>item1</li>
<li>item2</li>
<li>item3</li>
<li>item4</li>
<li>item5</li>
<li>item6</li>
<li>item7</li>
<li>item8</li>
</ul>
</body>
</html>
/* CSS文件 */
/* 选择第一个 */
li:nth-of-type(1) {
background-color: blue;
}
/* 选择最后一个 */
li:nth-last-of-type(1) {
border: 5px solid violet;
}
/* 选择全部 */
li:nth-of-type(n) {
background-color: blueviolet;
}
/* 选择奇数 */
li:nth-of-type(2n+1) {
background-color: yellow;
}
/* 选择前三个 */
li:nth-of-type(-n+3) {
background-color: cornflowerblue;
}
/* 选择最后三个 */
li:nth-last-of-type(-n+3) {
background-color: aqua;
}
/* 选择偶数 */
li:nth-of-type(even) {
color: brown;
}
/* 选择奇数 */
li:nth-of-type(odd) {
border: 5px solid red;
}
<!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>盒模型</title>
<link rel="stylesheet" href="css/style2.css">
</head>
<body>
<div class="box">我是盒子</div>
</body>
</html>
/* CSS代码 */
.box {
height: 150px;
width: 200px;
background-clip: content-box;
border: 3px dashed yellowgreen;
box-sizing: border-box;
margin: 0px;
padding: 5px;
background-color: blueviolet;
color: burlywood;
}
相关推荐
© 2020 asciim码
人生就是一场修行