我有以下CSS:
table.Table12 { border:1px solid blue; }
table.Table12 td { border:1px solid blue; width:200px;}
table.Table12 a:link{ font-weight: bold;}
和下面的html代码:
<table class="Table12" align="right">
<tr><td><a href="http://www.example.com/test1.php">test1</a></td>
<td><a href="http://www.example.com/test2.php">test2</a></td></tr>
<tr><td><a href="http://www.example.com/test3.php">test3</a></td>
<td><a href="http://www.example.com/test4.php">test4</a></td></tr>
</table>
一切正常,我将所有表格设置为粗体字体; 我只需要在CSS中将“test3”的字体改为普通字体; 这可能吗?
答案 0 :(得分:2)
在css中试试这个:
table.Table12 td:nth-child(3) { font-weight: normal; }
忘记了......没有考虑你的css代码的最后一行。 这个工作正常:
table.Table12 tr:nth-child(2) td:nth-child(2) a { font-weight: normal; }
您可以在此处找到有关nth-child
语法的更多详细信息:How can I get the second child using CSS?
答案 1 :(得分:1)
Nik的答案是对的,你不需要在HTML中添加它,而是将它添加到CSS中。应该加到最后。 像这样:
table.Table12 { border:1px solid blue; }
table.Table12 td { border:1px solid blue; width:200px;}
table.Table12 a:link{ font-weight: bold;}
/*Solution*/
table.Table12 td:nth-child(2) { font-weight: normal; }
这将立即奏效。
您还可以为其添加一个类,然后将其回收以供以后使用:
.normal-font{font-weight: normal}
然后在你的HTML中:
<table class="Table12" align="right">
<tr><td><a href="http://www.example.com/test1.php">test1</a></td>
<td><a href="http://www.example.com/test2.php">test2</a></td></tr>
<tr><td><a href="http://www.example.com/test3.php" class="normal-font">test3</a></td>
<td><a href="http://www.example.com/test4.php">test4</a></td></tr>
</table>