3.7序选择器/伪类选择器

111 阅读1分钟
<!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>Document</title>
	<style>
		/* 序选择器 伪类选择器 nth-child(n/odd(奇数)/even(偶数)/表达式)    */
		p:first-child{
			color: yellow;
		}
		p:last-child{
			color: pink;
		}
		p:nth-child(5){
			color: blue;
		}
		/* 选取奇数p标签 */
		p:nth-child(odd){
			background-color: red;
		}
		/* 选取偶数p标签 */
		p:nth-child(even){
			background-color: blue;
		}
		/* 1 4 7  3n+1 n是从0开始的 */
		p:nth-child(3n+1){
			font-size: 28px;
		}
		/* 2 5 8 3n+2 */
		p:nth-child(3n+2){
			width: 100px;
		}

	</style>
</head>
<body>
	<p>段落标签</p>
	<p>段落标签</p>
	<p>段落标签</p>
	<p>段落标签</p>
	<p>段落标签</p>
	<p>段落标签</p>
	<p>段落标签</p>
	<p>段落标签</p>
</body>
</html>