1.first-child:选择其父元素的首个子元素的每个element元素 2.last-child:选择其父元素的最后一个子元素的每个element元素 3.nth-child():匹配属于其父元素的第N个子元素,不论元素的类型 3.1也可以使用n表达式运算,取值从0开始,只能是n不能是其他字母,比如所有奇数:2n+1 3.2固定参数:odd:所有奇数 3.3固定参数...
1 element:first-child选择属于其父元素的首个子元素的element元素 注意:div:first-child 必须是其父元素下面的第一个子元素且必须是div元素才能匹配的到 匹配结果: 2 同理:element:last-child指定其父元素的最后一个子元素的element元素 注意:div:last-child 代表其父元素的最后一个元素一定是div才能匹配到 3:n...
This CSS tutorial explains how to use the CSS selector called :first-child with syntax and examples. The CSS :first-child selector allows you to target an element that is the first child element within its parent.
:first-childpseudo class apply to an element if it is first sibling in all direct child elements of its parent. Here are some examples. :first-child positive example .foo > p:first-child { background-color:lightgreen; } p1 p2 ...
The :first-child selector matches the first child element.:first-child is a Pseudo-class and it applies to any element that is the first child of another element. With :first-child pseudo-class, an element is matched only when it is the first child of another element. For example, p:...
3.7、element[attr*=value] 匹配attr属性值中【包含】value的element元素 如:div[class*=on] 匹配class属性值中包含on的div元素 4、伪类选择器 4.1、目标伪类:突出显示活动的锚点元素 语法::target 如: a:target{} div:target{} 4.2、元素状态伪类:多数用在表单控件上,去匹配表单控件的不同状态 ...
To utilize the:first-child selector, follow this syntax: parentElement:first-child { /* Styles to be applied to the first child element */ } This may look a little confusing at first but let's take a closer look at some practical examples of the actual usage for this CSS selector. ...
- 语法: element::before {} - before 和 after 必须有 content 属性 - before 在父元素内容的前面创建元素,after 在父元素内容的后面插入元素 伪元素选择器和标签选择器一样,权重为 1 应用场景一: 字体图标 在实际工作中,字体图标基本上都是用伪元素来实现的,好处在于我们不需要在结构中额外去定义字体图标的...
element1~element2 p~div选择前面有元素的每个元素。 A标签伪类选择器 :linka:link 所有未被访问的链接(a标签的默认样式)。 :visiteda:visited 所有已被访问的链接。 :activea:active 点击后没有松开鼠标的链接。 :hovera:hover 鼠标指针位于其上的链接。 :before / ...