CSS3 :first-of-type 选择器

CSS3 :first-of-type 选择器

CSS完整选择器完整CSS选择器参考手册

定义和用法

:first-of-type选择器匹配元素其父级是特定类型的第一个子元素。

提示: 等同于 :nth-of-type(1)。


Examples

实例

实例

指定其父级的第一个p元素的背景色:

p:first-of-type
{
  background:#ff0000;
}

尝试一下 »

浏览器支持

表格中的数字表示支持该属性的第一个浏览器版本号。

选择器     
:first-of-type4.09.03.53.29.6

CSS完整选择器完整CSS选择器参考手册

目录

CSS基本选择器

CSS .class选择器
CSS #id选择器
CSS * 选择器
CSS element 选择器

CSS组合选择器

CSS element,element 选择器
CSS element element 选择器
CSS element>element 选择器
CSS element+element 选择器
CSS3 element1~element2 选择器

CSS属性选择器

CSS [attribute] 选择器
CSS [attribute=value] 选择器
CSS [attribute~=value] 选择器
CSS [attribute|=value] 选择器
CSS3 [attribute^=value] 选择器
CSS3 [attribute$=value] 选择器
CSS3 [attribute*=value] 选择器

CSS伪元素选择器

CSS :active 选择器
CSS :after 选择器
CSS :before 选择器
CSS3 :checked 选择器
CSS3 :disabled 选择器
CSS3 :empty 选择器
CSS3 :enabled 选择器
CSS :first-child 伪元素
CSS :first-letter 伪元素
CSS :first-line 伪元素
CSS3 :first-of-type 选择器
CSS :focus 选择器
CSS :hover 选择器
CSS :in-range选择器
CSS :invalid选择器
CSS :lang() 选择器
CSS3 :last-child 选择器
CSS3 :last-of-type 选择器
CSS :link 选择器
CSS3 :not 选择器
CSS3 :nth-child() 选择器
CSS3 :nth-last-child() 选择器
CSS3 :nth-last-of-type() 选择器
CSS3 :nth-of-type() 选择器
CSS3 :only-of-type 选择器
CSS3 :only-child 选择器
CSS :optional选择器
CSS :out-of-range选择器
CSS :read-only选择器
CSS :read-write选择器
CSS :required选择器
CSS3 :root 选择器
CSS3 ::selection 选择器
CSS3 :target 选择器
CSS :valid 选择器
CSS :visited 选择器

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }