本教程操作环境:Windows10系统、css3版,该方法适用于所有品牌电脑。
css匹配选择第n个子元素
加入要让第二个 th 占table表格总宽度的50%.
<style type = "text/css"> table tr th:nth-child(2) </style> <table> <tr> <th>第一个</th> <th>第二个</th> <th>第三个</th> </tr> </table>
定义:
:nth-child(n) 选择器匹配属于其父元素(在这里就是tr)的第 N (这里选择第2个)个子元素(这里子元素是th),不论元素的类型。
以上就是css如何实现选择第几个子元素的详细内容,更多请关注0133技术站其它相关文章!