在修改Bootstrap vanilla的CSS时,我发现了一个奇怪的闪烁效果,当你点击一个下拉菜单然后点击它之外(例如在体内):
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<style>
.navbar-default {
background-color: #222;
}
.navbar-default .navbar-brand,
.navbar-default .navbar-brand:hover,
.navbar-default .navbar-nav > li > a {
color: #FFF;
}
.navbar-default .navbar-nav > li > a:hover,
.navbar-default .navbar-nav > li > a:focus,
.navbar-default .navbar-nav > .dropdown > a:focus,
.navbar-default .navbar-nav > .open {
background-color: #444;
color: #FFF;
}
@media (min-width: 3000px) and (max-width: 3000px) {
.collapse {
display: none !important;
}
}
</style>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="#">Link <span class="sr-only">(current)</span></a>
</li>
<li><a href="#">Link</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a>
</li>
<li><a href="#">Another action</a>
</li>
<li><a href="#">Something else here</a>
</li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a>
</li>
<li role="separator" class="divider"></li>
<li><a href="#">One more separated link</a>
</li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Link</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a>
</li>
<li><a href="#">Another action</a>
</li>
<li><a href="#">Something else here</a>
</li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a>
</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
&#13;
要使代码段实际显示错误,您需要在整页内查看。
您是否知道我应该使用哪个css选择器进行修复?
答案 0 :(得分:1)
您需要的元素是a.dropdown-toggle。我不知道造型时有多少特定的引导,或者即使它使用内联式,但是如果你使用!important,你可以看到闪烁停止。
.dropdown-toggle {
background-color: transparent !important;
}
更新: Bootstrap使用:.nav .open&gt; a,.nav .open&gt; a:focus,.nav .open&gt; a:hover
答案 1 :(得分:0)
请查看以下链接,并告诉我它现在是否正常工作。
https://jsfiddle.net/98o4kakg/3/
.navbar-default .navbar-nav > .open {
background-color: #444;
color:#FFF;
}
答案 2 :(得分:0)
您需要在css中添加以下内容来设置下拉链接的样式而不是下拉列表:
.navbar-default .navbar-nav > .dropdown > a {
background-color:#222;
color:#FFF;
}
包含更多标签和类将在同一元素上的样式上保留higher priority,而无需额外的类。
例如:在类之前添加body
可以使类更具体。