:first-of-type 选择器匹配元素其父级是特定类型的第一个子元素。 提示:和 :nth-of-type(1) 是一个意思。 浏览器支持 表格中的数字表示支持该属性的第一个浏览器版本号。 选择器 :first-of-type4.09.03.53.29.6 完整CSS选择器参考手册 CSS3 [attribute*=value] 选择器 ...
first-of-type选择器 “:first-of-type”选择器类似于“:first-child”选择器,不同之处就是指定了元素的类型,其主要用来定位一个父元素下的某个类型的第一个子元素。 示例演示: 通过“:first-of-type”选择器,定位div容器中的第一个p元素(p不一定是容器中的第一个子元素),并设置其背景色为橙色。 HTML代...
css选择器, first-child,first-of-type 选择制定的classname var li = $('.list-tab-group li.active'); 1.通用元素选择器 选中所有的元素 <!DOCTYPE html>Title/*去掉块与块之间的间隙*/*{margin:0;padding:0;}测试通用元素匹配测试通用元素匹配测试通用元素匹配...
p:first-of-type h1:first-of-type span:first-of-type :first-of-type 所以,通过以上两个例子可以得出结论: :first-child 匹配的是某父元素的第一个子元素,可以说是结构上的第一个子元素。 :first-of-type 匹配的是该类型的第一个,类型是指什么呢,就是冒号前面匹配到的东西,比如 p:first-of-type,就...
:first-of-type p:first-of-type 选择属于其父元素的首个 p 元素的每个 p 元素。 3 :last-of-type p:last-of-type 选择属于其父元素的最后 p 元素的每个 p 元素。 3 :only-of-type p:only-of-type 选择属于其父元素唯一的p 元素的每个 p 元素。 3 :nth-of-type(n) p:nth-of-type(2) 选择...
:first-child & :first-of-type :first-child:选取在一组兄弟元素中的第一个元素。 :first-of-type:选取在一组兄弟元素中的第一个指定元素。 解释一下:比如p:first-child{},选择的就是p元素的兄弟元素的第一个元素,且这个元素必须是p元素才被选择;div:first-of-type就是选择div的兄弟元素中的第一个div...
1 应用代码。这个代码当中,它的父元素就是P。p:first-of-type{ background:#ff0000; } 2 完整style的流程。只要第一个这是第一个落。 有了颜色的变化。p:first-of-type{background:#ff0000;}这是标题这是第一个落。这是第二个。这是第三个。这是第四个。 3 CSS3 :last-of-type 选择器,这个选...
在CSS选择器中,有两个关键的区别选择器:`:first-child`和`:first-of-type`。`:first-child`选择的是一个元素作为其父元素的第一个子元素,关注的是结构上的顺序。例如,`p:first-child`匹配的是第一个``元素,因为它是其父元素``的第一个子元素。然而,`:first-of-type`则更进一步,它...
css选择器中first-child与first-of-type的区别 :first-child选择器是css2中定义的选择器,从字面意思上来看也很好理解,就是第一个子元素,匹配其父元素中的第一个子元素。 比如有段代码: p:first-child 匹配到的是p元素,因为p元素是p的第一个子元素;h2:first-child 匹配不到任何元素,因为在这里h2是p的第二...
区别::first-child匹配父元素中的第一个子元素,可以说是结构上的第一个子元素;而:first-of-type匹配父元素下相同类型子元素中的第一个,不再限制是第一个子元素了,只要是该类型元素的第一个就行了。 【推荐教程:CSS视频教程 】 css选择器中first-child与first-of-type的区别 ...