li:first-child{color:red} 2. last-child 选择列表中的最后一个标签 li:last-child{color:pink} 3.nth-child(n) 这里的n为数字,表示选择列表中的第n个标签 例如选择第三个标签 li:nth-child(3){color:pink} 4.nth-child(2n) 选择列表中的偶数,选中 2、4、6…… 个标签。 li:nth-child(2n){colo...
3.class选择器 可以同时选取 不同 的元素 <!DOCTYPE html>Title/*3.class选择器 可以选取 不同 的元素*/.tycs{height:50px;width:140px;background:deeppink;}测试通用元素匹配1测试通用元素匹配2测试通用元素匹配3 效果 所有的class同名被选中设置属性,最后一个是span元素不支持设置宽高 4.id选择器 id唯一 ...
1、first-child first-child表示选择列表中的第一个标签。代码如下: li:first-child{background:#090} 上面的意思是,li 列表中的 第一个li模块的背景颜色。 2、last-child last-child表示选择列表中的最后一个标签,代码如下: li:last-child{background:#090} 3、nth-child(3) 表示选择列表中的第3个标签,...
CSS :first-line 伪元素 CSS :lang() 选择器 CSS:first-child选择器 完整CSS选择器参考手册 实例 匹配 的父元素的第一个元素 p:first-child{background-color:yellow;} 尝试一下 » 定义和用法 :first-child 选择器匹配其父元素中的第一个子元素。 浏览器支持...
first-child表示的是選擇父元素的第一個子元素的元素E。簡單點理解就是選擇元素中的第一個子元素,記住是子元素,而不是後代元素。 结构性伪类选择器—first-child 表示的是选择父元素的第一个子元素的元素E。 简单点理解就是选择元素中的第一个子元素,记住是子元素,而不是后代元素。
first-child选择器的基本用法 first-child选择器的语法非常简单,它会选择父元素中的第一个子元素。例如: ulli:first-child {color: red; } 这段代码的意思是,选择元素中的第一个元素,并将其文本颜色设置为红色。 应用场景 列表样式控制: 在列表中,经常需要对第一个列表项进行特殊处理。例如,在导航菜单中,第...
The CSS :first-child pseudo-class selects the element if it is the first child among other elements. The :first-of-type selector can be used if the user wants to select and apply the style on the first paragraph. The :first-child selector is actually similar to :first-of-type but ...
In CSS, the:first-childpseudo-class is used to select the first child element within a parent element. This selector is often used for styling the first element of a list or the first paragraph of a section. Syntax The:first-childselector is written with a colon followed by the keyword...
:first-child 单独使用这个选择器不带任何前缀,选择的是作为 “某个元素” 的 “第一个子元素” 的元素 ,某个元素是文档里的任意元素(即所有元素),第一个子元素可以是任意的元素,要想明白这个子元素,很好的一个方式是使用jquery,在浏览器控制台使用 $(":last-child") 查看选择出来的元素就可以一目了然。