结构伪类选择器

第一个li元素

ul li:first-child{
			background-color: aqua;
		}

/* ul中的最后一个Li元素 *

​
ul li:last-child{
			background-color: aquamarine;
		}

​

/* 第n个子元素 */

.u2 li:nth-child(2){
			background-color: blue;
		}
p:nth-child(1){
	background-color:darkcyan;
}

/* 一般会加上父元素 */

li:nth-child(2){
			background-color: chartreuse;
		}

/* 先看数字再看类型 */

body p:nth-child(6){
			background-color: brown

/* 根据类型先看标签再看是第几个标签 先看类型再看数字*/

p:nth-of-type(2){
			background-color: blueviolet;
		}
		body p:nth-of-type(2){
			background-color: blueviolet;
		}

整体:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>结构伪类选择器</title>
	<style>
		/* 第一个li元素 */
		ul li:first-child{
			background-color: aqua;
		}
		/* ul中的最后一个Li元素 */
		ul li:last-child{
			background-color: aquamarine;
		}
		/* 第n个子元素 */
		p:nth-child(1){
			background-color:darkcyan;
		}
		/* 一般会加上父元素 */
		li:nth-child(2){
			background-color: chartreuse;
		}
		.u2 li:nth-child(2){
			background-color: blue;
		}
		/* 先看数字再看类型 */
		body p:nth-child(6){
			background-color: brown;
		}
		/* 根据类型先看标签再看是第几个标签 先看类型再看数字*/
		p:nth-of-type(2){
			background-color: blueviolet;
		}
		body p:nth-of-type(2){
			background-color: blueviolet;
		}
	</style>
	</head>
	<body>
		<p>1</p>
		<p>2</p>
		<p>3</p>
		<ul>
			<li>4</li>
			<li>5</li>
			<li>6</li>
		</ul>
		<ul class="u2">
			<li>7</li>
			<li>8</li>
			<li>9</li>
		</ul>
		<p>10</p>
	</body>
</html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值