我遇到了CSS声明优先级的问题。我的页面包含一个外部CSS文件和一些内联CSS声明,它们应该会覆盖掉那个规则。据我所知,内联样式声明应该会覆盖外部CSS声明。然而,当我在Chrome中查看页面时,表格的第二行显示为蓝色,而不是根据内部样式声明定义的红色。
我在哪里出错了?
以下是HTML代码:
这是CSS文件的内容:
我在哪里出错了?
以下是HTML代码:
<html>
<head>
<link rel="stylesheet" href="screen.css" type="text/css" media="screen, projection">
<style type="text/css">
td,tr,th
{
background: Red;
}
</style>
</head>
<body>
<table>
<tr>
<td>11</td>
<td>22</td>
</tr>
<tr>
<td>aa</td>
<td>bb</td>
</tr>
</table>
</body>
</html>
这是CSS文件的内容:
tbody tr:nth-child(even) td,
tbody tr.even td
{
background: #e5ecf9;
}
!important
- 参见https://dev59.com/FHA65IYBdhLWcg3wqAWt - andyb