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.
I got two things to add here…
using code sometimes as a child of an (regular inline) anchor, sometimes not:
You should add
line-height: normal
to kind of compensate for the inline-block, otherwise you will different paddings on linked elements than on others. (i.e. your line-height will easily start looking inconsistent)And optionally: If you were just annoyed, that the underline has a different color (i.e. the outer link color, rather than the green of
code
) settings text-decoration once again on that inner element helps…Try following css,
Demo
I had the same issue and fixed this using the following css rule:
hope it helps!
Simply add
display:inline-block;
FIDDLE DEMO
You can also write you HTML like
and CSS like
Set the
display
property ofi
toinline-block
:JSFiddle