2

I want to create an underline when I hover over the links in my navigation bar. I'm not sure which id I should be targeting. Here's my JFiddle: https://jsfiddle.net/gzycz4h8/

Thanks in advance.

<ul id="nav">
  <li><a href="#">About</a></li>
  <li><a href="#">Writing</a></li>
  <li><a href="#">Multimedia</a></li>
  <li><a href="#">Resume</a></li>
  <li><a href="#">Contact</a></li>
</ul>
dancemc15
  • 598
  • 2
  • 7
  • 21

3 Answers3

2

are you looking for something like this ?

#nav {
  padding: 10px 0;
  width:700px;
  margin: 0 auto;
  text-align: center;
  list-style-type: none;
  display:block;
  text-decoration: none;
  -webkit-box-shadow: 0 2px 10px -12px #999;
  -moz-box-shadow: 0 8px 6px -6px #999;
   box-shadow: 0 8px 6px -6px #999;
}

#nav li {
  display: inline-block;
  margin: 5px;
  text-transform: uppercase;

}
#nav li a {
  text-decoration:none;
}
#nav li a:hover {
    text-decoration: underline;
    text-decoration-color: black;
    -o-transition:.4s;
    -ms-transition:.4s;
    -moz-transition:.4s;
    -webkit-transition:.4s;
    transition:.4s;

}
Dhaval Chheda
  • 4,637
  • 5
  • 24
  • 44
2

The most simple solution would be:

li a {
  text-decoration:none;
}

li a:hover {
    text-decoration: underline;
}

https://jsfiddle.net/LvLsckzw/

Reto
  • 1,305
  • 1
  • 18
  • 32
1

Or something like this: https://jsfiddle.net/m16gggk1/1/

#nav {
  padding: 0;
  width:700px;
  margin: 0 auto;
  text-align: center;
  list-style-type: none;
  display:block;
  text-decoration: none;
  -webkit-box-shadow: 0 2px 10px -12px #999;
  -moz-box-shadow: 0 8px 6px -6px #999;
   box-shadow: 0 8px 6px -6px #999;
}

#nav li {
  display: inline-block;
  margin: 0 5px;
  text-transform: uppercase;
  border-bottom:2px solid #fff;

}
#nav li a {
  text-decoration:none;
}
#nav li a:hover {
  color:red;
}
#nav li:hover {
    border-bottom:2px solid red;


}
Rachel S
  • 3,780
  • 3
  • 24
  • 37
  • How can I create the transition though when I hover over my links? I want a delay when I hover over my text. I've included the transitions in my css – dancemc15 May 12 '16 at 19:46
  • You could have added them in yourself ;) but here you go: https://jsfiddle.net/m16gggk1/2/ – Rachel S May 12 '16 at 19:47
  • It's weird that I can't do it with text-decoration-underline. I think I would prefer that since with border, it actually makes everything else shift a bit? – dancemc15 May 12 '16 at 19:49
  • Sorry, and one more question. Why do you have 2 border bottoms? Thanks for being helpful – dancemc15 May 12 '16 at 19:51
  • 1
    If I just add a red border for hovering, the navbar will be jumpy each time you hover over a link because it extends the whole navbar. Therefore I added a white border to always be there (it looks hidden) to eliminate the jumpiness on hover. – Rachel S May 12 '16 at 20:08
  • Hey, I used the idea in this above js fiddle but when I hover over the nav-link, the content beneath in the container below the nav bar gets pushed down due to the generation of the bottom border. How should I prevent the down pushing? – Meet Gondaliya Jan 19 '22 at 10:02