结构伪类选择器

1.:first-child 整个结构中的第一个
:last-child 整个结构中的最后一个

2.:first-of-type :last-of-type 这个元素类型的第一个和最后一个

3.:nth-child(n) 整个结构中的第n个
n可以写成2n或even,指的是偶数
2n-1或2n+1或odd是奇数
:nth-of-type(n) 这个类型的第几个
4.:nth-last-child(n):整个结构中倒数第几个
:nth-last-of-type(n) 这个类型的倒数第n个

5.:only-child 整个结构只有一个标签,其他标签都不存在
:only-of-child 整个结构中这个类型的只有一个

6.:empty 当元素内容为空时的设置
7.:root选择文档的根节点

:root和html的区别:
:root的优先级高于html,html是指html文档的根节点,但是root不一定指html,也可能是其他文档结构

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style>
			h1:first-child{color:#ff0;}
			h1:last-child{color:#ff0;}
			
			div:first-of-type{color:#f00;}
			div:last-of-type{color:#f00;}
			
			div:nth-child(3){color:#0ff;}
			div:nth-of-type(3){color:#00f;}
			
			h1:nth-last-child(2){color:#999;}
			div:nth-last-of-type(2){color:#f0f;}
		</style>
		
		
	</head>
	<body>
		<h1>1</h1>
		<div>div1</div>
		<div>div2</div>
		<div>div3</div>
		<div>div4</div>
		<div>div5</div>
		<div>div6</div>
		<div>div7</div>
		<div>div8</div>
		<div>div9</div>
		<div>div10</div>
		<h1>2</h1>
		<h1>3</h1>
	</body>
</html>

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值