Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove underline from a link and add underline on hover? (images attached)

I want underline to be removed from a link. Also I want underline to appear when I hover it with my mouse pointer. How can this be done? Pls help.

No hover: NO Hover - Normal link

When I hover the Login link: When I hover the Login link

like image 883
sumit Avatar asked Jul 02 '11 10:07

sumit


People also ask

How do you hover underline in HTML?

Using HTML, CSS create an animated underline effect when the user hovers over the text. Use display: inline-block to make the underline span just the width of the text content. Use the :after pseudo-element with width: 100% and position: absolute to place it below the content.

How do you change the underline on a link?

Change the underline to dots with the border-bottom style property a { text-decoration: none; border-bottom:1px dotted; }. Change the underline color by typing a { text-decoration: none; border-bottom:1px solid red; }. Replace solid red with another color.


2 Answers

You need to turn off the CSS property text-decoration for the link and then use the :hover dynamic pseudo class to add the text-decoration back when hovering.

a {
    text-decoration:none;
}

a:hover {
   text-decoration:underline;
}

Demo

Also, you might also need to style the :visited:hover pseudo class so that the underline appears on links a user has already visited. link order in css is a good answer because the order of the CSS rules matters.

like image 144
andyb Avatar answered Oct 19 '22 16:10

andyb


Assuming your login link has the id login...

#login {
   text-decoration: none;
}

#login:hover {
   text-decoration: underline;
}
like image 1
alex Avatar answered Oct 19 '22 17:10

alex