bootstrap4导航栏下划线

时间:2018-02-23 11:31:39

标签: html css bootstrap-4 navbar

请帮助...我的导航栏中的下划线无效。这是我的HTML和css文件:https://jsfiddle.net/57fd6yf5/1/ 我希望光标在菜单下激活下划线,但不在徽标下。我猜这个问题是在css文件中。

HTML:

      <nav class="navbar navbar-expand-md navbar-light bg-dark">
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarNav">
      <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="#">O MNIE</a>
        </li>
        <li class="nav-logo">
          <a href="#"><img id="logo-navbar" src="images/logo.png" width="60px" height="60px"></a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">PORTFOLIO</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">KONTAKT</a>
        </li>
      </ul>
    </div>
  </nav>

CSS:

.nav-link{
  font-size: 20px;
}
.nav-item{
  padding: 15px 30px;
}
.nav-logo{
  padding: 10px 10px
}

.navbar-collapse {
  justify-content: center;
}
.navbar-light .navbar-nav .active::after{
  position: absolute;
  bottom: -10px;
  left: 0;
  right: 0;
  width: 100%
  content: " ";
  color: #F4C127;
  border-bottom: 5px solid #F4C127;
}
.navbar-nav > li {
  float: left;
  position: relative;
}

2 个答案:

答案 0 :(得分:0)

你应该替换这个css。您的课程应为.navbar-light .navbar-nav li.active

.navbar-light .navbar-nav li.active::after{
  position: absolute;
  bottom: -10px;
  left: 0;
  right: 0;
  width: 100%;
  content: " ";
  color: #F4C127;
  border-bottom: 5px solid #F4C127;
}

答案 1 :(得分:0)

要使border-bottom位于活动链接项下,您需要以下css规则:

.navbar-light .navbar-nav .active>.nav-link {
    border-bottom: 5px solid #F4C127;
}

但是,如果您希望边框位于整个导航栏的底部,那么(如@ZimSystem所指出的那样)您需要将缺少的;添加到您的css中的width: 100%部分规则。