003css3结构伪类选择器和属性选择器

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>css3结构伪类选择器和属性选择器</title>
<style>
li:hover{}

/*1、结构选择器*/
	li:first-child{
		color: red;
	}
	ul li:last-child{
		color: pink;
	}
	/*	ul li:second-child{
		color: blue;     z这是错误的写法
	}*/

/*语法:nth-child(n)  选中间的li*/
	ul li:nth-child(3){
		color: blue;
	}
	ul li:nth-child(4){
		color: green;
	}

/*选择所有的偶数*/
	ul li:nth-child(even){     /*even表示偶数*/
		background-color: purple;
	}

/*选择所有奇数*/
	ul li:nth-child(odd){    /*odd选择所有奇数*/
		background-color: yellow;
	}

/*选择所有的Li*/
	ul li:nth-child(n){
		margin-top: 10px;
	}

/*2n表示偶数的li*/
	ul li:nth-child(2n){    /*2n=even*/
		margin-top: 10px;
	}

/*2n+1表示奇数的li*/
	ul li:nth-child(2n+1){    /*2n+1=odd*/
		margin-top: 10px;
	}




/*2、属性选择器*/

/*选择所有的class元素*/
	div[class]{
		color: red;
	}

/*选出class=one的*/
	div[class=one]{
		color: pink;
	}

/*以three开头的class给选出来*/
	div[class^=three]{
		color: yellow;
	}

/*以three结尾的class选出来*/
	div[class$=three]{
		color: blue;
	}

/*选择所有带有test的class*/
	div[class*=three]{
		color: purple;
	}

</style>
</head>
<body>
<!-- 1、结构选择器 -->
	<ul>
		<li>大桥</li>
		<li>小青</li>
		<li>小哈</li>
		<li>笑话</li>
		<li>啊哈</li>
	</ul>

<!-- 2、属性选择器 -->
	<div class="one">王者荣耀</div>
	<div class="two">刺激战场</div>

	<div class="firstthree">刺激战场</div>
	<div class="three">王者荣耀</div>
	<div class="three1">刺激战场</div>
	<div class="three2">刺激战场</div>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值