Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple underline colors in one anchor

Tags:

html

css

I would like to, within one anchor </a>, have two different underline colors. Like so:

<a href="somehref">
    <span>This text should underline RED on `a` hover</span>
    <span>This text should underline GREY on `a` hover</span>
</a>

I can add text-decoration to each span on hover but this causes each line to hover individually. I want it so that when I hover over anywhere in the </a> both spans underline with their font color inherited.

Is this possible?

Note: I'm aware of text-decoration-color but due to limit support I cannot use it.

like image 956
Geraint Avatar asked Jul 20 '16 12:07

Geraint


People also ask

How do I change the color of the underline in anchor tag?

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

How do I get rid of the blue underline in anchor tag?

To remove underline from a link in HTML, use the CSS property text-decoration. Use it with the style attribute. The style attribute specifies an inline style for an element. Use the style attribute with the CSS property text-decoration to remove underline from a link in HTML.


1 Answers

Some thing like this? You can use the anchor's :hover CSS pseudo class to style it's child and descendant.

Here is an reference to CSS child and descendant selectors.

a {
  color: black;
  text-decoration: none;
}
a span:first-child {
  color: red;
}
a span:last-child {
  color: grey;
}
a:hover span {
  text-decoration: underline;
}
<a href="somehref">
  <span>This text should underline RED on `a` hover</span>
  <span>This text should underline GREY on `a` hover</span>
</a>
like image 200
Pugazh Avatar answered Oct 01 '22 17:10

Pugazh