特定表格中每行的第一个单元格的CSS样式

39

我有一个ID为"student"的表格。 例如:

 <table id="student">
    <tr>
        <td>Role</td>
        <td>Merin</td>
        <td>Nakarmi</td>
    </tr>
    <tr>
        <td>Role</td>
        <td>Tchelen</td>
        <td>Lilian</td>
    </tr>
    <tr>
        <td>Role</td>
        <td>Suraj</td>
        <td>Shrestha</td>
    </tr>
</table>

对于此表中的每一行,第一个 <td> 的值为“Role”,我想隐藏每一行的这个第一个 <td>

我尝试了以下选项:

#student > tr > td:first-child
{ 
    width: 0px; important;
}

但不幸的是它没有起作用。

请帮忙。

3个回答

78
使用以下内容。
table#student tr td:first-child{display:none;}

工作演示


给你 Nathan。 https://dev59.com/C2Ij5IYBdhLWcg3wmWK1 - Merin Nakarmi
回答 - @MerinNakarmi - Nitesh

2

您的代码不正确:

{ width: 0px; important; }

this should be:

#student > tr > td:first-child{ 
  width: 0px !important; 
}

在使用 important 属性之前,您使用了分号,这是不正确的。


1
 #student > tr > td:first-child{
  display : none;
    }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接