:nth-last-child(n) 选择器匹配属于其元素的第 N 个子元素的每个元素,不论元素的类型,从最后一个子元素开始计数。n可以是一个数字,一个关键字,或者一个公式。提示: 请参阅 :nth-last-of-type() 选择器。该选择器匹配父元素中的倒数第n个结构子元素。
li:nth-child(n+5){background:#0ab1fc;} nth-last-child(n)nth-last-child(n):选择倒数第 n 个元素。 举例:倒数第三元素字体设置为红色,代码如下: 代码语言:javascript 复制 li:nth-last-child(3){color:red;} 同样可以使用上面的方法进行拓展,方法如下: nth-last-child(n+n)nth-last-child(n+n)...
li:nth-child(n+4){color:pink} 7. 选择从第一个到第四个 这里的数字4也是可以根据你的需要替换的。 li:nth-child(-n+4){color:pink} 8.nth-last-child(3) 表示最后三个标签 li:nth-last-child(3){color:pink} 9.nth-last-child(3n) 表示3的倍数3.6.9…… li:nth-last-child(3n){color:pin...
li:nth-last-child(n + 5) ~ li { width: 50%; display: inline-block; border-bottom: 0; } 虽然这很有效,但在某些方面仍然有点局限性。 不可能根据元素的数量来设计父元素的样式 想象一下,当有5个或更多的项时,我们需要为每个添加display: flex。我们不能用:nth-last-child伪类选择器来做这个。 原...
This CSS tutorial explains how to use the CSS selector called :nth-last-child with syntax and examples. The CSS :nth-last-child selector allows you to target an element that is the nth last child element within its parent.
我们可以通过 CSS 来实现这样的效果,CSS 给我们提供了几个结构伪类选择器:first-child、last-child、nth-child(n)。 二、基本使用方法 1.常见使用方法 first-child:选择列表中的第一个标签。 举例:第一行字体显示为红色,代码如下: li:first-child{
: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...
:nth-last-child(n) 选择器匹配属于其元素的第 N 个子元素的每个元素,不论元素的类型,从最后一个子元素开始计数。n 可以是数字、关键词或公式。提示:请参阅 :nth-of-type() 选择器,该选择器选取父元素的第 N 个指定类型的子元素。更多实例 实例1 ...
介绍一下常用的css3结构伪类选择器,nth-child、nth-last-child、nth-of-type、nth-last-of-type、first-child、last-child 、first-of-type 、last-of-type、only-child以及only-of-type。结构性伪类选择器的公共特征是允许开发者根据文档结构来指定元素的样式。接下来开始进入正题。
first-child表示选择列表中的第一个标签。代码如下: li:first-child{background:#090} 上面的意思是,li 列表中的 第一个li模块的背景颜色。 2、last-child last-child表示选择列表中的最后一个标签,代码如下: li:last-child{background:#090} 3、nth-child(3) ...