题解 | CSS选择器——伪类选择器

CSS选择器——伪类选择器

https://www.nowcoder.com/practice/d8a08991f6294e98b7b78597483ab2b8

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <style>
       /* 填写样式 */
	   /* 结构伪类选择器  E:nth-child(n)  选择父元素的第n个子元素E */
       ul li:nth-child(2n) {
        background-color:rgb(255,0,0);
       }
    </style>
</head>

<body>
  <ul>
	<li>1</li>
	<li>2</li>
	<li>3</li>
	<li>4</li>
</ul> 
    <script type="text/javascript">
        /* 填写JavaScript */
        
    </script>
</body>

</html>

结构伪类选择器(n=0,1,2,3...)

1.E:first-child 父元素的第一个子元素E

2.E:last-child 父元素的最后一个子元素E

3.E:nth-child(n) 父元素的第n个子元素E

4.E:first-of-type 指定类型E的第一个

5.E:last-of-type 指定类型E的最后一个

6.E:nth-of-type(n) 指定类型E的第n个

type和child区别:

child:先找第n个 再匹配E E不同则匹配不上

type:先找E 再找第n个

全部评论

相关推荐

10-19 14:15
兰州大学 Java
_Philia093:蓝桥杯省三删掉
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务