我有以下引导程序导航栏:JSBin:
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-default navbar-static-top" ng-controller="NavCtrl">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdow <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="https://www.google.fr">New</a></li>
<li><a href="https://www.google.fr">Old</a></li>
</ul>
</li>
<li><a href="https://www.google.fr">Help</a></li>
</ul>
</nav>
</body>
</html>
&#13;
我想做以下事情:
#e1e1e1
dropdown
和help
上时,该元素的背景颜色会变得更暗(例如,#a9a9a9
)有谁知道如何实现这个目标?
答案 0 :(得分:2)
使用这些规则对其进行定位,以覆盖默认的引导样式。
.navbar-default {
background-color: #e1e1e1;
}
.navbar-default .navbar-nav>li>a:focus,
.navbar-default .navbar-nav>li>a:hover,
.navbar-default .navbar-nav .open .dropdown-menu>li>a:focus,
.navbar-default .navbar-nav .open .dropdown-menu>li>a:hover {
background: #a9a9a9;
}
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<style>
.navbar-default {
background-color: #e1e1e1;
}
nav.navbar-default .navbar-nav>li>a:focus,
nav.navbar-default .navbar-nav .open .dropdown-menu>li>a:focus,
nav.navbar-default .navbar-nav>li>a:hover,
nav.navbar-default .navbar-nav .open .dropdown-menu>li>a:hover {
background: #a9a9a9;
}
</style>
</head>
<body>
<nav class="navbar navbar-default navbar-static-top" ng-controller="NavCtrl">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdow <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="https://www.google.fr">New</a></li>
<li><a href="https://www.google.fr">Old</a></li>
</ul>
</li>
<li><a href="https://www.google.fr">Help</a></li>
</ul>
</nav>
</body>
</html>
&#13;
答案 1 :(得分:1)
您只需选择要更改的元素
.navbar {
background-color: #e1e1e1;
}
nav li:hover {
background-color: #a9a9a9;
}
答案 2 :(得分:1)
这是你需要的吗?
.nav li {
background: #e1e1e1;
}
.nav li:hover {
background: #a1a1a1;
}
&#13;
<script src="https://code.jquery.com/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<body>
<nav class="navbar navbar-default navbar-static-top" ng-controller="NavCtrl">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdow <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="https://www.google.fr">New</a></li>
<li><a href="https://www.google.fr">Old</a></li>
</ul>
</li>
<li><a href="https://www.google.fr">Help</a></li>
</ul>
</nav>
&#13;