对于快速解决方案,您可以简单地使您的 css 规则更具体:
body .Category{
display:table-row-group;
//other properties not related to this problem not shown
}
假设您有以下代码:
<html>
<head>
<style>
div{background-color:#ccc}
#content .Category{display:block;}
.template{display:none;}
.otherdiv{background-color:red;}
body .otherdiv{background-color:green;}
</style>
</head>
<body>
<div id="content">
<div class="template Category" >inner template div</div>
</div>
<div class="template">outer template div</div>
<div class="otherdiv">outer other div</div>
</body>
</html>
将inner template div
显示为 bloc,但外部不会。
你的css规则更具体,它们更“自然重要”。在我的代码中,div.otherdiv
将显示为绿色,因为它body .otherdiv
比.otherdiv
请参阅有关 css 特异性的文章http://coding.smashingmagazine.com/2007/07/27/css-specificity-things-you-should-know/
“从0开始,样式属性加1000,每个ID加100,每个属性、类或伪类加10,每个元素名称或伪元素加1。”
完全不推荐使用!important
,并非所有浏览器都支持