:nth-child(odd)或者:nth-child(2n+1)奇数行、:nth-child(even)或者:nth-child(2n+2)偶数行 :nth-last-child(n) p::nth-last-child(n)同上,从最后一个子元素开始计数。 :empty p:empty选择没有子元素的每个<p>元素(包括文本节点)。 :not(selector) :not(p)选择非<p>元素的每个元素。 input状态...
li:last-child { background-color: red; } 3):nth-child(n):选取父元素中第n个子元素。 示例:将列表中的奇数位置的项目的背景色改为蓝色: li:nth-child(odd) { background-color: blue; } 3.4否定伪类选择器 这类选择器用于排除符合特定条件的元素。例如: :not(selector):选取不符合括号内选择器的所...
:not 伪类选择器可以筛选不符合表达式的元素,:not(selector)其中的selector为css选择器 ul li:not(:first-child) ul li:not(.text) //不包含class="text"的元素 :not(p) //非段落元素 ul li:not(:first-child):not(:last-child) //not可叠加使用 jQuery中.not()方法 not() 从匹配元素集合中删除元...
要使用CSS选择元素中除最后一个之外的所有子元素,可以使用使用:not和:last-child选择器。 语法: element:not(:last-child) { // CSS样式 } :not(selector) 选择器:用来匹配非指定元素/选择器的每个元素。 :last-child选择器:用来匹配父元素中最后一个子元素。 示例1:创建一个导航菜单,除最后一个元素外,菜...
CSS结构伪类选择器之否定伪类:not() 结构伪类选择器是针对 HTML 层级结构的伪类选择器。 常用的结构化伪类选择器有: :root选择器、:not选择器、:only-child选择器、:first-child选择器、:last-child选择器、 :nth-child选择器、:nth-child(n)选择器、:nth-last-child(n)选择器、:nth-of-type(n)选择器、...
选择属性值以特定值结尾的元素:如p[spec&='len2']选择spec属性值以len2结尾的元素。伪类选择器:如p:nthchild选择第一个p元素,p:nthlastchild选择倒数第一个p元素。CSS Selector提供了一种灵活且强大的方式来定位网页中的元素,广泛应用于网页开发、测试和自动化脚本中。
:nth-child选择器、:nth-child(n)选择器、:nth-last-child(n)选择器、:nth-of-type(n)选择器、 :empty选择器、:target选择器。 这些基本上都很常用,今天着重说下:否定伪类:not() 否定伪类特别有用,在css中, :not选择器 用于匹配非指定元素/选择器的每个元素,语法格式: ...
3):nth-child(n):选取父元素中第n个子元素。 示例:将列表中的奇数位置的项目的背景色改为蓝色: li:nth-child(odd){background-color:blue;} 3.4否定伪类选择器 这类选择器用于排除符合特定条件的元素。例如: :not(selector):选取不符合括号内选择器的所有元素。
CSS last-child selector: select last-element of specific class, not last child inside of parent? However, if your last .red sometimes is in different positions, and you can't change the HTML at all, then you will have to rely on some light JS/jQuery. $(function() { ...
4.3.4、:only-child 匹配属于其父元素中的唯一子元素 4.3.5、:nth-child(n)匹配属于其父元素中的第n个子元素 4.4、否定伪类:将匹配的元素排除在外 语法::not(selector); 5、伪元素选择器 5.1、::first-letter 获取匹配元素的第一个字母(字符)