gpt4 book ai didi

html - Bootstrap 下拉菜单事件类

转载 作者:行者123 更新时间:2023-11-28 01:40:24 27 4
gpt4 key购买 nike

我正在尝试使用 Bootstrap 创建导航栏,但是当我将事件类重定向到下拉菜单时,所有子菜单都会收到事件类。我只希望元素部分使用事件类

<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse"
data-target="#example-navbar-collapse">
<span class="sr-only"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="example-navbar-collapse">
<ul class="nav navbar-nav">
<li><a href="index.html">About</a></li>
<li class="dropdown active">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Project <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><a href="project.html">AAAA</a></li>
<li><a href="#">BBB</a></li>
<li><a href="#">CCC</a></li>
<li><a href="#">DDD</a></li>
</ul>
</li>
<li><a href="team.html">Team</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</div>
</nav>

最佳答案

您需要使用 .navbar-default .navbar-nav>.active>a { //styles here for active li }以事件 <li> 为目标只是,像这样:

.dropdown-menu {
display: block !important;
}
.navbar-default .navbar-nav>.active>a {
color: blue !important;
background: red !important;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#example-navbar-collapse">
<span class="sr-only"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="example-navbar-collapse">
<ul class="nav navbar-nav">
<li><a href="index.html">About</a>
</li>
<li class="dropdown active">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Project <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><a href="project.html">AAAA</a>
</li>
<li><a href="#">BBB</a>
</li>
<li><a href="#">CCC</a>
</li>
<li><a href="#">DDD</a>
</li>
</ul>
</li>
<li><a href="team.html">Team</a>
</li>
<li><a href="contact.html">Contact</a>
</li>
</ul>
</div>
</nav>

关于html - Bootstrap 下拉菜单事件类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26497198/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com