mozilla
您的搜索结果

    :first-child

    概述

    CSS伪类 :first-child代表了某个元素,这个元素是它父元素的的第一个子元素.

    语法

    element:first-child { style properties }
    

    示例

    span:first-child {
        background-color: lime;
    }
    

    上面的CSS作用于下面的HTML:

    <div>
      <span>This span is limed!</span>
      <span>This span is not. :(</span>
    </div>
    

    就会显示出这样的效果:
    This span is limed! This span is not. :(

    规范

    Specification Status Comment
    Selectors Level 4
    :first-child
    Working Draft No change.
    Selectors Level 3
    :first-child
    Recommendation Initial definition.

    浏览器兼容性

    Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
    Basic support 4.0 3.0 (1.9) 7 9.5 4
    Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
    Basic support 1.0 1.0 (1.9.1) 7 10.0 3.1

    IE附注

    Internet Explorer 7 doesn't update the styles when elements are added dynamically. In Internet Explorer 8, if an element is inserted dynamically by clicking on a link the first-child style isn't applied until the link loses focus.

    文档标签和贡献者

    Contributors to this page: teoli, ziyunfei, FredWe
    最后编辑者: FredWe,