1.first-child:选择其父元素的首个子元素的每个element元素 2.last-child:选择其父元素的最后一个子元素的每个element元素 3.nth-child():匹配属于其父元素的第N个子元素,不论元素的类型 3.1也可以使用n表达式运算,取值从0开始,只能是n不能是其他字母,比如所有奇数:2n+1 3.2固定参数:odd:所有奇数 3.3固定参数...
selector::pseudo-element { property: value; } p::first-line{ color: #ff0000; } h1::before{ content: '♥'; } 3、常用伪元素选择器 伪元素选择器并不是针对真正的元素使用的选择器,而是针对CSS中已经定义好的伪元素使用的选择器,CSS中有如下四种常用伪元素选择器:first-line、 first-letter、 befo...
:first-child p:first-child匹配的是某父元素的第一个子元素,可以说是结构上的第一个子元素。(注意和:first-of-type做区分) :first-of-type p:first-of-type匹配的是该类型的第一个,类型是指什么呢,就是冒号前面匹配到的东西,比如 p:first-of-type,就是指所有p元素中的第一个。这里不再限制是第一个...
1 element:first-child选择属于其父元素的首个子元素的element元素 注意:div:first-child 必须是其父元素下面的第一个子元素且必须是div元素才能匹配的到 匹配结果: 2 同理:element:last-child指定其父元素的最后一个子元素的element元素 注意:div:last-child 代表其父元素的最后一个元素一定是div才能匹配到 ...
: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:...
- 语法: element::before {} - before 和 after 必须有 content 属性 - before 在父元素内容的前面创建元素,after 在父元素内容的后面插入元素 伪元素选择器和标签选择器一样,权重为 1 应用场景一: 字体图标 在实际工作中,字体图标基本上都是用伪元素来实现的,好处在于我们不需要在结构中额外去定义字体图标的...
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.
3.7、element[attr*=value] 匹配attr属性值中【包含】value的element元素 如:div[class*=on] 匹配class属性值中包含on的div元素 4、伪类选择器 4.1、目标伪类:突出显示活动的锚点元素 语法::target 如: a:target{} div:target{} 4.2、元素状态伪类:多数用在表单控件上,去匹配表单控件的不同状态 ...