1

HTML:

<div class="collapse navbar-collapse navbar-ex1-collapse">
  <ul id="menu-primary" class="nav navbar-nav menustyle">
    <li><a href="#">Home</a></li>
  </ul>
</div>

CSS:

.menustyle a:before{
  position: absolute;
  top: 0;
  left: 0;
  content: "";
  height: 2px;
  background-color: #fff;
  width: 0%;
}
.nav > li > a:hover .menustyle a:before{
  width: 100%!important;
}

This is not working when I use Bootstrap but works without bootstrap.

Ramesh KR
  • 143
  • 1
  • 9

2 Answers2

3

Try to use .nav > li > a:hover:before instead of .nav > li > a:hover .menustyle a:before...

.nav > li > a:hover .menustyle a:before....means it will target all the .menustyle a elements inside a <a> tag.

.nav > li > a:hover:before {
  width: 100%;
}

Fiddle Link

Bhuwan
  • 16,525
  • 5
  • 34
  • 57
  • @RameshKR you want to give fixed width to all ..? – Bhuwan Feb 09 '18 at 05:42
  • @RameshKR - That is a completely different question and should be asked separately. Good answer and nice explanation, Bhuwan, +1. – Roddy of the Frozen Peas Feb 09 '18 at 05:45
  • Because I can't ask a question right now StackOverflow restricted me. – Ramesh KR Feb 09 '18 at 06:02