Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Underlining an html anchor with different color

Tags:

html

css

anchor

Is it possible to underline an anchor tag with a color other than its text color? Any example will be appreciated.

EDIT: Is it possible to specify color as hex e.g. #8f867c ?

like image 762
Umer Hayat Avatar asked May 07 '12 10:05

Umer Hayat


People also ask

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

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.

How do you change the color of an underline?

Change the underline style and color Select the text that you want to underline. Tip: You can also use the keyboard shortcut Ctrl+D. Use the Underline style drop-down list to select an underline style. Use the Underline color drop-down list to change the color of the line.

How do I change the color of an inline CSS anchor?

Complete HTML/CSS Course 2022 To change the color of links in HTML, use the CSS property color. Use it with the style attribute. The style attribute specifies an inline style for an element. Use the style attribute with the CSS property color to change the link color.


2 Answers

CSS3 allows you to use text-decoration-color: #8f867c to set the color directly.

p {
  color: green;
  text-decoration: underline;
  text-decoration-color: #8f867c;
}

span {
  color: #8f867c;
}
<p>My underline is <span>#8f867c</span></p>
like image 111
Chad Avatar answered Sep 19 '22 14:09

Chad


You cannot specify the underline color separately, but you can use a little trick:

a {
    color: red;
    text-decoration: none;
    border-bottom: 1px solid green;
}

Note that the border will not appear exactly where the underline would have appeared, sorry.

like image 20
Salman A Avatar answered Sep 17 '22 14:09

Salman A