我想更改nav-item
中的某些样式。我制作了另一个样式表,并制作了这段代码。问题在于,在Internet Explorer中它可以正常工作,但在Firefox中没有任何变化。如何在nav-link active
中进行一些更改?
例如,我想在导航处于活动状态时在边框底部添加一个
<div class="container">
<nav class="navbar navbar-expand-lg navbar-light py-md-5">
<a class="navbar-brand" href="#">Navbar</a>
<div class="justify-content-end collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav">
<a class="nav-item nav-link active" href="#">Home <span class="sr-only">(current)</span></a>
<a class="nav-item nav-link" href="#">ABOUT US</a>
<a class="nav-item nav-link" href="#">SERVICES</a>
<a class="nav-item nav-link" href="#">TEAM</a>
<a class="nav-item nav-link" href="#">CLIENTS</a>
<a class="nav-item nav-link" href="#">CONTACT</a>
</div>
</div>
</nav>
</div>
答案 0 :(得分:2)
以您的自定义样式添加此CSS
TS
.nav-item.active
{
border-bottom:2px solid #f00;
}
.nav-item.active
{
border-bottom:2px solid #f00;
}
答案 1 :(得分:0)
$('.nav-link').click(function() {
$('.nav-link').removeClass("active");
$('li.nav-item.active').removeClass("active");
$(this).addClass("active");
});
.active {
border-bottom: 2px solid #f00;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<nav class="navbar navbar-expand-lg navbar-light py-md-5">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="justify-content-end collapse navbar-collapse" id="collapsibleNavbar">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home </a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">ABOUT US</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">SERVICES</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">TEAM</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">CLIENTS</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">CONTACT</a>
</li>
</ul>
</div>
</nav>