我正在引导4中的导航栏上工作。我将鼠标悬停在导航链接上时遇到问题。我在导航链接的悬停下方添加了边框底部。但是当悬停完成后,整个导航栏就会移动。我已经粘贴了到目前为止所做的事情。
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">
<img src="#" />
</a>
<button class="navbar-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 mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">First item</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Second Item</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
<div class="my-2 my-lg-0">
</div>
</div>
</nav>
<style>
.navbar-dark .navbar-nav .nav-link:hover,
.navbar-dark .navbar-nav .nav-link:focus {
color: rgba(255, 255, 255, 0.75);
border-bottom: 2px solid #fff;
}
</style>
答案 0 :(得分:0)
它移动的原因是因为您没有边框,然后在悬停时突然添加了2px边框。解决此问题的方法是在常规/未悬停状态下添加2px透明边框。
.navbar-dark .navbar-nav .nav-link {
border-bottom: 2px solid transparent;
}