css进阶01选择器

增加的选择器

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>Title</title>
		<style>
		/* :nth-of-type(n) 选择器匹配属于父元素的特定类型的第 N 个子元素的每个元素.n 可以是数字、关键词或公式。 */
			p:first-of-type{
				color: red;
			}
			p:last-of-type{
				color: #0000FF;
			}
			p:nth-of-type(2){
				color: #000000;
			}
			p:nth-last-of-type(2){
				color: greenyellow;
			}
		</style>
	</head>
	<body>
		<div>
			<span></span>
			<p>1</p>
			<a></a>
			<p>2</p>
			<p>3</p>
			<div></div>
			<p>4</p>
		</div>
	</body>
</html>

在这里插入图片描述

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>Title</title>
		<style>
			/*:nth-child(n) 选择器匹配属于其父元素的第 N 个子元素,不论元素的类型。*/
			span:first-child {
				color: red;
			}

			p:last-child {
				color: #0000FF;
			}

			p:nth-child(2) {
				color: gold;
			}

			p:nth-last-child(4) {
				font-size: 45px;
			}
			div:nth-child(6){
				font-size: 24px;
			}
		</style>
	</head>
	<body>
		<div>
			<span>span</span>
			<p>1</p>
			<a>a</a>
			<p>2</p>
			<p>3</p>
			<div>div1</div>
			<div>div2</div>
			<p>4</p>
		</div>
	</body>
</html>


在这里插入图片描述

::selection等

::selection 选择用户鼠标选中部分
:not 选择非用户指定内容的选择器
:root 更节点选择器

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>Title</title>
		<style>
			/* ::root 设置网页根元素*/
			:root {
				background-color: #FFE4C4;

			}

			/* :not()除了指定元素外的yuans */
			.box :not(p) {
				background-color: pink;
			}

			/* ::selection 改变双击后用户选中的元素的背景颜色 */
			div::selection {
				background-color: #FF0000;
			}

			span:first-child {
				color: red;
			}

			p:last-child {
				color: #0000FF;
			}

			p:nth-child(2) {
				color: gold;
			}

			p:nth-last-child(4) {
				font-size: 45px;
			}

			div:nth-child(6) {
				font-size: 24px;
			}
		</style>
	</head>
	<body>
		<div class="box">
			<span>span</span>
			<p>1</p>
			<a>a</a>
			<p>2</p>
			<p>3</p>
			<div>div1</div>
			<div>div2</div>
			<p>4</p>
		</div>
	</body>
</html>

在这里插入图片描述

:enabled等

:enabled选择状态可用的元素(input, button)
:disabled选择状态不可用的元素(input, button)
:checked选择选中状态下的input标签
[attr = " value "] 属性选择器

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>Title</title>
		<style>
			input[type='radio'] {
				width: 25px;
				height: 25px;
			}
			input[type='radio']:checked {
				width: 45px;
				height: 45px;
			}

			input[type="text"] {
				width: 250px;
			}

			input[type="text"]:enabled {
				border: 1px dashed green;
			}

			/* ::root 设置网页根元素*/
			:root {
				background-color: #FFE4C4;

			}

			/* :not()除了指定元素外的yuans */
			.box :not(p) {
				background-color: pink;
			}

			/* ::selection 改变双击后用户选中的元素的背景颜色 */
			div::selection {
				background-color: #FF0000;
			}

			span:first-child {
				color: red;
			}

			p:last-child {
				color: #0000FF;
			}

			p:nth-child(2) {
				color: gold;
			}

			p:nth-last-child(4) {
				font-size: 45px;
			}

			div:nth-child(6) {
				font-size: 24px;
			}
		</style>
	</head>
	<body>
		<div class="box">
			<input type="text">
			<div></div>
			<input type="radio">
			<input type="radio"> 
			<div></div>
			<input type="checkbox" name="" id="" value="" />
			<span>span</span>
			<p>1</p>
			<a>a</a>
			<p>2</p>
			<p>3</p>
			<div>div1</div>
			<div>div2</div>
			<p>4</p>
		</div>
	</body>
</html>

target选择器

在这里插入图片描述

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>Title</title>
		<style>
			#news1:target {
				color: green;
			}

			#news2:target {
				color: red;
			}


			input[type='radio'] {
				width: 25px;
				height: 25px;
			}

			input[type='radio']:checked {
				width: 45px;
				height: 45px;
			}

			input[type="text"] {
				width: 250px;
			}

			input[type="text"]:enabled {
				border: 1px dashed green;
			}

			/* ::root 设置网页根元素*/
			:root {
				background-color: #FFE4C4;

			}

			/* :not()除了指定元素外的yuans */
			.box :not(p) {
				background-color: pink;
			}

			/* ::selection 改变双击后用户选中的元素的背景颜色 */
			div::selection {
				background-color: #FF0000;
			}

			span:first-child {
				color: red;
			}

			p:last-child {
				color: #0000FF;
			}

			p:nth-child(2) {
				color: gold;
			}

			p:nth-last-child(4) {
				font-size: 45px;
			}

			div:nth-child(6) {
				font-size: 24px;
			}
		</style>
	</head>
	<body>
		<div class="box">
			<input type="text">
			<div></div>
			<input type="radio">
			<input type="radio">
			<div></div>
			<input type="checkbox" name="" id="" value="" />
			<span>span</span>
			<p>1</p>
			<a>a</a>
			<p>2</p>
			<p>3</p>
			<div>div1</div>
			<div>div2</div>
			<p>4</p>
		</div>


		<div>
			<a href="#news1">点我让news1变绿</a>
			<a href="#news2">点我让news2变红</a>
			<div id="news1">
				news1
			</div>
			<div id="news2">
				news2
			</div>
		</div>
	</body>
</html>

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值