使用CSS 3选择第一个表中的第一个td

比如我说:
<div id="container">
    <table>
        <tr>
            <td></td>
            <td></td>
        </tr>

        <tr>
            <td></td>
            <td></td>
        </tr>
    </table>

    <table>
        <tr>
            <td></td>
            <td></td>
        </tr>

        <tr>
            <td></td>
            <td></td>
        </tr>
    </table>
</div>

td { width:10px; height:10px; }

我想做的是将样式应用到第一个表的第一个td.

我本来会期待:

#container table:first-child td:first-child {
    background: red;
}

但是它不行吗?请指教!

解决方法

#container table:first-child tr:first-child td:first-child { background: red; }

似乎工作
请注意,在IE下,您将需要在您的HTML中有一个!DOCTYPE声明来获得:first-child的支持. http://www.w3schools.com/cssref/sel_firstchild.asp

相关文章

Css3如何实现鼠标移上变长特效?(图文+视频)
css3怎么实现鼠标悬停图片时缓慢变大效果?(图文+视频)
jquery如何实现点击网页回到顶部效果?(图文+视频)
css3边框阴影效果怎么做?(图文+视频)
css怎么实现圆角边框和圆形效果?(图文+视频教程)
Css3如何实现旋转移动动画特效