怎样才能使单元格的左边框变红?为什么这不起作用?谢谢!!
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
.main-table {
border-collapse: collapse;
}
.main-table td {
margin: 0px;
padding: 0px;
border: 1px solid #aaa;
padding: 1px 4px 1px 4px;
}
.left-border {
border-left: 1px solid red !important;
}
</style>
</head>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
左边框不应该覆盖.main-table td上指定的颜色吗?
<table class='main-table' cellspacing='0' cellpadding='0'>
<tr>
<td> 1 </td>
<td> 366 </td>
</tr>
<tr>
<td > 2 </td>
<td class='left-border'> 777 </td>
</tr>
</table>
</body>
</html>
发布于 2012-01-18 15:06:52
将边框设置为1px double red
。1px宽的“双”边框看起来与“实体”边框相同,但在折叠边框计算中具有更高的优先级。
发布于 2012-01-18 15:03:23
尝尝这个,
.main-table {
border-collapse: collapse;
}
.left-border {
border-left: 2px solid red !important;
}
发布于 2012-01-18 15:09:31
在CSS中,最具体的选择器优先于次要的选择器。例如,在您的示例中,.main-table td
优先于.left-border
,因为前者更具体。要解决此问题,可以为边界替代指定:.main-table td.left-border
。这比使用!important
更正确,也更好,因为它消除了进一步覆盖它的所有机会。
有关CSS选择器优先级的信息,请参阅此链接:http://www.vanseodesign.com/css/css-specificity-inheritance-cascaade/
https://stackoverflow.com/questions/8906313
复制相似问题