1、first-child first-child表示选择列表中的第一个标签。代码如下: li:first-child{background:#090} 上面的意思是,li 列表中的 第一个li模块的背景颜色。 2、last-child last-child表示选择列表中的最后一个标签,代码如下: li:last-child{background:#090} 3、nth-child(3) 表示选择列表中的第3个标签,...
我们可以通过另外的方法选择奇数行,例如: nth-child(n+1) 、 nth-child(2n-1) 等。 代码如下: 代码语言:javascript 代码运行次数:0 复制 Cloud Studio代码运行 /*First*/li:nth-child(n+1){background:#999;}/*Second*/li:nth-child(2n-1){background:#999;} nth-child(even)nth-child(even):选择...
1.first-child 选择列表中的第一个标签 li:first-child{color:red} 2. last-child 选择列表中的最后一个标签 li:last-child{color:pink} 3.nth-child(n) 这里的n为数字,表示选择列表中的第n个标签 例如选择第三个标签 li:nth-child(3){color:pink} 4.nth-child(2n) 选择列表中的偶数,选中 2、4、6...
1、first-child first-child表示选择列表中的第一个标签。例如:li:first-child{background:#fff} 2、last-child last-child表示选择列表中的最后一个标签,例如:li:last-child{background:#fff} 3、nth-child(3) 表示选择列表中的第3个标签,例如:li:nth-child(3){background:#fff},代码中的3也可以改成其...
:nth-last-of-type()也一样: 同样选择到了最后一个div元素,并不受最后一个p元素的影响。 总结 在以上八个伪类选择器中,:first-child:last-child:nth-child(n):nth-last-child(n)在选择元素时,是按照其所有类型的兄弟元素开始计数,而:first-of-type:last-of-type:nth-of-type(n)nth-last-of-type(n...
使用not、nth-of-type、nth-child三种选择器 &:not(:first-child){ background-color: #eee; } &:not(:last-child):hover{ background-color: #d7d7d7; } // 取应用了className的,倒数第三个节点之外的节点 .className:not(:nth-last-child(3)) {} 发布...
:nth-child() 选择器,该选择器选取父元素的第 N 个子元素,与类型无关。 一、偶数:nth-child(2n) 二、奇数 :nth-child(2n-1) 三、第6个开始的,直到最后:nth-child(n+6) 四、选择第1个到第6个 :nth-child(-n+6) 五、两者结合使用,可以限制选择某一个范围,选择第6个到第9个 :nth-child(n+6...
last-child表示选择列表中的最后一个标签,代码如下: li:last-child{background:#090} 3、nth-child(3) 表示选择列表中的第3个标签,代码如下: li:nth-child(3){background:#090} 上面代码中的3也可以改成其它数字,如4、5等。想选择第几个标签,就填写几。
:last-child 选择器用来匹配父元素中最后一个子元素。 提示:p:last-child 等同于 p:nth-last-child(1)。 浏览器支持 表格中的数字表示支持该属性的第一个浏览器版本号。 选择器 :last-child4.09.03.53.29.6 更多实例 实例 指定父元素 ul 中最后一个 li 元素,并设置背景颜色: ...
例如使列表中的第一项或者最后一项显示不同的样式 、列表中的奇数或者偶数项显示不同的背景色 . . . 等等。 我们可以通过 CSS 来实现这样的效果,CSS 给我们提供了几个结构伪类选择器:first-child、last-child、nth-child(n)。 二、基本使用方法 1.常见使用方法 ...