我的页面中有两个列表。第一个在 #main
元素中,第二个在 #footer
元素中。由于 #footer
元素位于 #main
元素内,因此这些是我的规则:
body div#wrap_all div#main div#footer div.widget_nav_menu ul#menu-footer li {
border-right: 1px solid #D2AB67;
display: inline-block !important;
padding: 0 10px;
}
/* I dont want this rules below to be applied to the list in the footer */
body div#wrap_all div#main section.avia_widget_section ul li {
border-bottom: 1px solid #E0D3CD;
font-family: "Georgia";
font-size: 17px;
font-style: italic;
padding: 7px 0 0 22px; /* O_o this rule is overwritten of course */
}
问题:第一个列表的规则也适用于 .footer
元素中的列表。我该怎么做才能避免这种情况?
最佳答案
第一个选择器显然比第二个有更多的分数,所以我只是建议通过在选择器中定义更多步骤来使第二个规则更精确。
当然,丑陋的解决方案是在 css 值的末尾使用 !important
:
padding: 7px 0 0 22px !important;
但我强烈建议重写您的 css 选择器,而不是使用 !important
。
关于css - 我希望规则被覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21265452/