伪类2

伪类的分类

1.状态伪类
状态伪类

2.结构性伪类

关键字

:first-child 选择元素的第一个子元素
:last-child 选择某个元素的最后一个子元素
:nth-child() 选择某个元素的一个或多个特定的子元素
:nth-last-child() 选择某个元素的一个或多个特定的子元素,从这个元素的最后一个子元素开始算
:first-of-type 选择一个上级元素下的一个同类子元素

示例

<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>
		结构伪类器
		</title>
		<link rel="stylesheet" type="text/css" href="jiegouweilei.css"/>
	</head>
	<body>
		<p> 测试2</p><br>
		<p> 测试3</p><br>
		<p> 测试4</p><br>
		<p> 测试1</p><br>
		<p> 测试1</p><br>
		<table border="1" width="500" >
			<tr>
				<th>1</th>
				<th>1</th>
				<th>1</th>
			</tr>
			<tr>
				<th>1</th>
				<th>1</th>
				<th>1</th>
			</tr>
			<tr>
				<th>1</th>
				<th>1</th>
				<th>1</th>
			</tr>
		</label>
	</body>
</html>

p:first-child{
	/* 父元素 第一个才会被选中  第一行标签必须是p */
	background-color: #0000FF;
}
p:first-of-type{
	/* body 里面 第一个p标签里面的背景 */
	background-color: #FF0000;
}
p:last-child{
	/* body 里面最后一行p标签下 设置属性 */
	background-color: #0000FF;
}
p:nth-child(2){
	/**
	 * body 里面p标签第2个背景设置颜色
	 */
	background-color: red;
}
tr:nth-child(2){
	background-color: #FF0000;
}

在这里插入图片描述
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值