我试图在悬停/聚焦时更改glyphicon的背景颜色而在我的横幅中没有成功.Below是2个glyphicons的代码片段,即 glyphicon-user 和 glyphicon登录即可。即使我在css中设置了另一种颜色,背景也会变为白色。
1.HTML
<div class="row">
<div class="col-sm-6 col-md-offset-4 col-md-4">
<a id="logo" href="#"> <img src="../static/images/logo_small.png" data-medium="../static/images/logo_medium.png" data-large="../static/images/logo_large.png"></a>
</div>
<div class="col-sm-6 col-md-4">
<ul class="nav navbar-nav pull-right">
<li><a class="custom-white" href="#"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
<li><a class="custom-white" href="#"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
</ul>
</div>
2.css
.custom-white { color:#fff;}
.custom-white:hover,
.custom-white:active,
.custom-white:focus {background-color: yellow;}
答案 0 :(得分:1)
在属性值
之后添加!important
工作demo
.custom-white:hover,
.custom-white:active,
.custom-white:focus {background-color: yellow !important;}
答案 1 :(得分:0)
尝试将CSS更改为:
.nav>li>a.custom-white:hover,
.nav>li>a.custom-white:active,
.nav>li>a.custom-white:focus {background-color: yellow;}
请参阅this demo
HTH, -Ted
答案 2 :(得分:0)
只需使用“!important”css功能覆盖bootstrap css即可。例如,
.custom-white:hover,
.custom-white:active,
.custome-white:focus
{background-color: yellow !important;}
否则,浏览器将首先编译bootstrap的默认值。希望有效!
答案 3 :(得分:0)
试试这个, 只需更新您的导航线路
即可.nav>li>a:hover,
.nav>li>a:active,
.nav>li>a:focus {background-color: yellow;}