Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove underline only from anchor element child

Tags:

css

When an a tag contains child elements, like an i tag, it's still applying the underline to it on hover, and I'm wondering how to remove the underline from just the i tag when someone hovers over the a tag.

The CSS I'm working with:

a{
    display:block;
    text-decoration:none;
}
a i{
  color:#888;
  margin-left:5px;
}
a:hover{
    text-decoration:underline;
}
a:hover i{
    text-decoration:none !important;
}

Here is a fiddle to explain: http://jsfiddle.net/kkz66x2q/

I simply would like the underline to be GONE only on the i element when you hover over the link.

like image 441
Control Freak Avatar asked Sep 10 '14 09:09

Control Freak


3 Answers

Try following css,

a:hover i{
    display: inline-block; <-- this is the trick
    text-decoration:none !important;
}

Demo

like image 105
Chamika Sandamal Avatar answered Oct 19 '22 03:10

Chamika Sandamal


Set the display property of i to inline-block:

a i {
    ...
    display: inline-block;
}

JSFiddle

like image 26
Karlen Kishmiryan Avatar answered Oct 19 '22 03:10

Karlen Kishmiryan


I had the same issue and fixed this using the following css rule:

a:-webkit-any-link {text-decoration:none}

hope it helps!

like image 1
Lorenzo Meriggi Avatar answered Oct 19 '22 04:10

Lorenzo Meriggi