我的网站上的导航栏出现问题。我想用浅红色的悬停效果让它变成红色,但出于某种原因它会变成红色和黑色。
如何修复颜色?
.navbar-inverse {
background-color: #cc0001;
}

<nav class="navbar navbar-inverse navbar-static-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="index.html"><img src="..\images\rpm.png" id="logo" /></a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active"><a href="index.html">Home</a></li>
<li class="active"><a href="videos.html">Videos</a></li>
<li class="active"><a href="aboutus.html">About us</a></li>
<li class="active"><a href="contactus.html">Contact us</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
</ul>
</div>
</div>
</nav>
&#13;
答案 0 :(得分:0)
你应该使用:hover {}来提供悬停效果。
.navbar-inverse {
background-color: #f50c0c !important;
border-color: #080808;
}
.active a:hover {
background-color: pink !important;
}
.nav li a{
background-color: red !important;
}
&#13;
<nav class="navbar navbar-inverse navbar-static-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="index.html"><img src="..\images\rpm.png" id="logo" /></a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active"><a href="index.html">Home</a></li>
<li class="active"><a href="videos.html">Videos</a></li>
<li class="active"><a href="aboutus.html">About us</a></li>
<li class="active"><a href="contactus.html">Contact us</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
</ul>
</div>
</div>
</nav>
&#13;
答案 1 :(得分:0)
您需要记住什么?
navbar-nav li:hover
在悬停时添加自定义灯光背景幕,如下所述。.navbar-nav li.active a
。
.navbar-inverse {
background-color: #cc0001 !important;
}
.navbar-nav li a:hover{
background-color: #ff3232 !important;
color:white;
}
.navbar-nav li.active a{
background-color: #ff0000 !important;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<nav class="navbar navbar-inverse navbar-static-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="index.html"><img src="http://via.placeholder.com/50x50" id="logo" /></a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active"><a href="index.html">Home</a></li>
<li><a href="videos.html">Videos</a></li>
<li><a href="aboutus.html">About us</a></li>
<li><a href="contactus.html">Contact us</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
</ul>
</div>
</div>
</nav>