我在另一个表中有一个HTML表。这两个表的样式都在CSS中定义。我想要内部和外部表具有不同的边框颜色。但是内表以某种方式呈现外表的边框颜色。下面是代码-
HTML:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="common.css">
</head>
<body>
<table width="100%" class="OuterTableStyle1"><tr><td>
<table width="100%" class="CommonTableStyle1" >
<tr>
<th>Title 1</th>
<th>Title 2</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
</table>
</td></tr></table>
</body>
</html>
CSS:
/*======= Start : Common data table style =========*/
table.CommonTableStyle1 td
{
vertical-align:middle;
padding:5px;
font-size:11px;
font-family:Arial;
font-weight:normal;
color:#000000;
}
table.CommonTableStyle1 th, table.CommonTableStyle1 td
{
border: 1px solid #525272 ;
}
table.CommonTableStyle1
{
border-collapse:collapse;
}
/*======= End : Common data table style =========*/
/*=== Start : This table is used as border of another scrollable table ===*/
table.OuterTableStyle1
{
border-collapse:collapse;
}
table.OuterTableStyle1 th, table.OuterTableStyle1 td
{
border: 1px solid red;
}
/*=== End : This table is used as border of another scrollable table ===*/
请帮忙。
[编辑的CSS]
/*======= Start : Common data table style =========*/
table.CommonTableStyle1 td
{
vertical-align:middle;
padding:5px;
font-size:11px;
font-family:Arial;
font-weight:normal;
color:#000000;
}
table.CommonTableStyle1 th, table.CommonTableStyle1 td
{
border: 1px solid #525272 ;
}
table.CommonTableStyle1
{
border-collapse:collapse;
}
/*======= End : Common data table style =========*/
/*=== Start : This table is used as border of another scrollable table ===*/
table.OuterTableStyle1
{
border-collapse:collapse;
border: 1px solid red;
}
/*=== End : This table is used as border of another scrollable table ===*/
最佳答案
选择器
table.CommonTableStyle1 table, th, td
无法正常工作,因为该表中没有包含“ CommonTableStyle1”类的表。
我认为您打算这样做:
table.CommonTableStyle1 th, table.CommonTableStyle1 td
见fiddle
另外,最底下的选择器确实起作用了,但不是您可能认为的那样。
th, td
部分与上面的部分具有相同的特异性,因此对于所有th
和td
都将采用这种样式,因为该样式稍后出现。但是现在还可以,因为我们已经提高了上面一种的特异性。