如何在不使用style属性的情况下从已应用于父级的css属性中排除某些元素

时间:2012-05-31 12:02:23

标签: html css

我的表是自动生成的,所以我不能给它上课。我所能做的只是白色的通用CSS,如下所示

td{white-space:nowrap}
a{white-space:normal}

如何为文本2和文本3提供text1正常空格但nowrap?

<tr>
<td>
<a href=""...>text 1</a>
</td>
<td>
text 2
</td>
<td>
text3
</td
</tr>

3 个答案:

答案 0 :(得分:2)

td { white-space:nowrap; }
td a { white-space:normal; }

记得要有

td a {..}

之后

td {..}

答案 1 :(得分:1)

如果您的链接始终位于行的第一个单元格中,则可以使用

解决
tr td:first-child { white-space : nowrap }
a { white-space : normal }

(我没有其他解决方案的线索)

答案 2 :(得分:0)

你也可以这样使用css中的伪元素。

table tr td a {white-space:normal} table tr td + td a {white-space:normal; }