CSS选择器是用于选择HTML元素并应用CSS样式的工具。它们帮助开发者精确地定位页面中的元素,以便为其添加样式或进行布局调整。 2. :nth-child()选择器的语法和基本用法 :nth-child() 是一个伪类选择器,用于选择属于其父元素的第N个子元素,不论这些子元素的类型是什么。其基本语法如下: css selector:nth-child(...
:nth-child(2)选取第几个标签,“2可以是你想要的数字” .demo01 li:nth-child(2){background:#090} :nth-child(n+4)选取大于等于4标签,“n”表示从整数,下同 点此查看实例展示 .demo01 li:nth-child(n+4){background:#090} :nth-child(-n+4)选取小于等于4标签 点此查看实例展示 .demo01 li:nt...
(1):first-child、:last-child、:nth-child(n)、:only-child (2):first-of-type、:last-of-type、:nth-of-type(n)、:only-of-type 一、:first-child、:last-child、:nth-child(n)、:only-child 子元素伪类选择器(第1类) 选择器 说明 E:first-child 选择父元素下的第一个子元素(该子元素类型为E...
/* ul li:nth-child(even) { background-color: pink; } ul li:nth-child(odd) { background-color: hotpink; } */ /* n 是公式 但是 n 从0开始计算 */ /* ul li:nth-child(n) { background-color: pink; } */ /* 2n 偶数 类似于 even */ /* ul li:nth-child(2n) { background-...
nth-child(4n+5) - 选择第5(4*0 + 5),第9(4*1 + 5),第13(4*2 + 5)个元素. 从解释中可以看出,该系列从第4个元素开始,然后重复.如果您需要从第一个元素(比如第一,第二,第五,第六等)开始,那么您可以使用选择器组作为div:nth-child(4n+1), div:nth-child(4n+2). div:nth-child(4n+4)...
css3 nth-child选择器 css3 nth-child选择器 css3的nth-child选择器,乍看起来很简单,其实不是那么容易。 简单用法 p:nth-child(n) // 选择属于其父元素的第n个子元素的每个 <p> 元素 p:nth-child(2n) // 选择属于其父元素的子元素的每个偶数<p> 元素...
HTML5+CSS——08子元素伪类、兄弟元素选择器、否定伪类、样式继承、选择器优先级、伪类顺序 一.子元素的伪类 1):first-child 可以选中第一个子元素 2):last-child 可以选中最后一个子元素 3):nth-child 可以选中任意一个子元素 该选择器可以指定一个参数,指定要选中第几个元素...
<!DOCTYPE html><html><head><metacharset="utf-8"><title>子元素的伪类</title><styletype="text/css">/*:first-child -选择第一个子标签 :last-child -选择最后一个子标签. :nth-child( ) 该选择器后面可以指定一个参数,指定要选中的第几个子元素 ...
使用css 选择器:not(target)明确选择要排除的子项。用另一个选择器替换target。 我们可以组合选择器:not()和:nth-child()来排除特定元素。 例如在这种情况下,我们要排除第 5 个和第 6 个元素,然后使用::not(:nth-child(5))和:not(:nth -child(6)). ...
:nth-child()选择某个元素的一个或多个特定的子元素 :nth-last-child()选择某个元素的一个或多个特定的子元素, 从这个元素的最后一个子元素开始算 :nth-of-type()选择指定的元素 :nth-last-of-type()选择指定的元素,从元素的最后一个开始计算