简体   繁体   English

如何取消先前规定的CSS规则? (背景颜色)

[英]How to suppress a previously stated CSS rule? (background-color)

In bootstrap there is a css rule that says 在引导程序中,有一个CSS规则指出

.nav>li>a:focus, .nav>li>a:hover {
    text-decoration: none;
    background-color: #eee;
}

I would like to suppress the rule background-color without overwriting it. 我想抑制规则background-color而不覆盖它。
Because if I add this to my custom style.css: 因为如果我将其添加到我的自定义style.css中:

.nav>li>a:focus, .nav>li>a:hover {
    background-color: inherit;
}

... the elements will have a white background. ...元素将具有白色背景。

The desired effect is to suppress the line background-color: #eee; 所需的效果是抑制行background-color: #eee;

To keep the color defined in the class .btn-primary. 保留在.btn-primary类中定义的颜色。

The HTML looks like this HTML看起来像这样

<ul class="nav nav-pills nav-stacked">
    <li role="presentation"><a class="btn btn-info" href="#">AAA</a></li>
    <li role="presentation"><a class="btn btn-primary" href="#">BBB</a></li>
</ul>

In the head section of your HTML, include your custom.css file after bootstrap.css and add !important after inherit . 在HTML的head ,在bootstrap.css之后添加custom.css文件,并在inherit之后添加!important

It should do the trick. 它应该可以解决问题。

.nav>li>a:focus, .nav>li>a:hover {
    background-color: inherit !important;
}

Or you can use unset : 或者您可以使用unset

.nav>li>a:focus, .nav>li>a:hover {
    background-color: unset !important;
}

https://developer.mozilla.org/en/docs/Web/CSS/unset https://developer.mozilla.org/en/docs/Web/CSS/unset

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM