ines b. ines b. - 5 months ago 8
HTML Question

Add a border at the bottom of the menu on hover and active

I'm trying to get this:
trying

But don't get it (lol) and having this instead:
having

Don't know where to adjust the thing.



@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');

.navbar-default .navbar-nav > li > a:hover,
.navbar-default .navbar-nav > li > a:focus {
color: black;
box-shadow: inset 0px -6px 0px #000;
}
.navbar-default .navbar-nav > .active > a,
.navbar-default .navbar-nav > .active > a:hover,
.navbar-default .navbar-nav > .active > a:focus {
color: black;
box-shadow: inset 0px -6px 0px #000;
}
#menu {
height: 140px;
}

<header>
<nav class="navbar navbar-default" id="menu">
<div class="container-fluid">
<div class="row">
<div class="col-md-3 col-sm-3">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">
<img alt="Brand" src="img/logo.png" height="100px;">
</a>
</div>
</div>
<div class="col-md-9 col-sm-9">
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav ">
<li class="active"><a href="#">Accueil <span class="sr-only">(current)</span></a></li>
<li><a href="#">Page 1</a></li>
<li><a href="#">Page 2</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
</div>
</div>
</div>
</nav>
</header>





Do you have any idea ? When i tried to fix it with the height it increased the navbar height...

Answer

Try to add this code:

.navbar-default .navbar-nav > li > a {
  line-height: 140px; /* = height of #menu */
  padding-bottom: 0;
  padding-top: 0;
}

Check the result:

@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');

.navbar-default .navbar-nav > li > a:hover,
.navbar-default .navbar-nav > li > a:focus {
  color: black;
  box-shadow: inset 0px -6px 0px #000; 

}
.navbar-default .navbar-nav > .active > a,
.navbar-default .navbar-nav > .active > a:hover,
.navbar-default .navbar-nav > .active > a:focus {
  color: black;
  box-shadow: inset 0px -6px 0px #000; 
}

#menu {
  height: 140px;
}
.navbar-default .navbar-nav > li > a {
  line-height: 140px; /* = height of #menu */
  padding-bottom: 0;
  padding-top: 0;
}
<header>
  <nav class="navbar navbar-default" id="menu">
    <div class="container-fluid">
      <div class="row">
        <div class="col-md-3 col-sm-3">
          <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
              <span class="sr-only">Toggle navigation</span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="index.html">
              <img alt="Brand" src="img/logo.png" height="100px;">
            </a>
          </div>
        </div>
        <div class="col-md-9 col-sm-9">
          <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav ">
              <li class="active"><a href="#">Accueil <span class="sr-only">(current)</span></a></li>
              <li><a href="#">Page 1</a></li>
              <li><a href="#">Page 2</a></li>
              <li><a href="#">Contact</a></li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </nav>
</header>

Comments