CSS3 - :first-child,:nth-child(1) 失效

html

logo

article1
article2
article3

css

article:first-child {
    color: red;

article:nth-child(1) {
    color: red;
}​

原因

    使用:first-child伪类时一定要保证前面没有兄弟节点,把h1去掉就可以;或者使用div包住article,然后css:div.article:first-child

    或者使用first-of-type

article:first-of-type {
    color: red;
}​

http://css.doyoe.com/selectors/pseudo-classes/first-child.htm
http://css.doyoe.com/selectors/pseudo-classes/first-of-type.htm

你可能感兴趣的:(css3)