E:first-child { sRules }
示例代碼:
- 列表項(xiàng)一
- 列表項(xiàng)二
- 列表項(xiàng)三
- 列表項(xiàng)四
在上述代碼中,如果我們要設(shè)置第一個(gè)li的樣式,那么代碼應(yīng)該寫成li:first-child{sRules}
,而不是ul:first-child{sRules}
。
示例代碼:
p:first-child{color:#f00;}
我是一個(gè)p
這段代碼你能看到p元素被命中變成了紅色
示例代碼:
p:first-child{color:#f00;}
我是一個(gè)標(biāo)題
我是一個(gè)p
只是在p前面加了一個(gè)h2標(biāo)簽,你會(huì)發(fā)現(xiàn)選擇器失效了,沒有命中p,why?
IE | Firefox | Chrome | Safari | Opera | iOS Safari | Android Browser | Android Chrome |
---|---|---|---|---|---|---|---|
6.0 | 2.0+ | 4.0+ | 3.1+ | 3.5+ | 3.2+ | 2.1+ | 18.0+ |
IE7.0+ |