我有一个带有链接的导航栏,我添加了活动类。为此活动类我添加了文本修饰css属性。我的问题是我想在文本和下划线之间添加间隙。我也使用border bottom属性,但是在屏幕尺寸小于992px,底线覆盖了整个div,我不是那个人。有人可以帮助我
HTML:
<nav class="navbar navbar-expand-lg navBgcolor fixed-top">
<a class="navbar-brand hiddenDiv" href="#">Bootstrap</a>
<button class="navbar-toggler custom-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link active" href="index.html">HOME</a>
</li>
<li class="nav-item">
<a class="nav-link" href="application.html">JOIN OUR TEAM</a>
</li>
<li class="nav-item">
<a class="nav-link" href="enrollment.html">ADMISSIONS</a>
</li>
</ul>
</div>
</nav>
CSS:
<style>
.navbar .nav-item > .nav-link.active {
text-decoration: underline;
text-decoration-color: #BB202E;
}
</style>
答案 0 :(得分:0)
您可以对:after
菜单元素使用.active
来尝试以下解决方案,以显示边框。使用top
值,您可以调整文本和边框之间的间距:
.navbar .nav-item > .nav-link.active {
display:inline-block;
position:relative;
}
.navbar .nav-item > .nav-link.active:after {
content: "";
position: absolute;
top: 80%;
background: #BB202E;
height: 2px;
left:0;
right:0;
}
@media (min-width: 992px) {
.navbar .nav-item > .nav-link.active:after {
left: .5rem;
right: .5rem;
}
}
<!-- bootstrap files -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<!-- navbar -->
<nav class="navbar navbar-expand-lg navBgcolor fixed-top">
<a class="navbar-brand hiddenDiv" href="#">Bootstrap</a>
<button class="navbar-toggler custom-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link active" href="index.html">HOME</a>
</li>
<li class="nav-item">
<a class="nav-link" href="application.html">JOIN OUR TEAM</a>
</li>
<li class="nav-item">
<a class="nav-link" href="enrollment.html">ADMISSIONS</a>
</li>
</ul>
</div>
</nav>