css - 我希望规则被覆盖

标签 css

我的页面中有两个列表。第一个在 #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/

相关文章:

html - 100% height div wrapper 展开 100% height children

twitter-bootstrap - Bootstrap 4 如何以居中和垂直方式布置窄文本

ios - iOS 8 上的 Flexbox - 框折叠

javascript - 单击元素时将元素 ID 传递给 js 函数

html - css 位置固定在 div 内

css - 当元素嵌套时覆盖 em 字体大小

javascript - CSS 如何设置自定义复选框勾号的 "content"/"background"属性的样式?

css - 媒体查询和 css LESS FRAMEWORK 4

javascript - 多行输出文本

css - Bootstrap - 如何水平排列元素而不分解它们?