13

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 ?

4

5 回答 5

22

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.

于 2012-05-07T10:03:59.490 回答
4

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>

于 2021-04-17T04:45:15.087 回答
3

Assuming you want the "border" to only show when user moves his mouse over it you should do something like this:

a {
  text-decoration: none;
}

a:hover {
  border-bottom: 1px solid blue;
  text-decoration: none;
}
于 2012-05-07T10:06:08.287 回答
2

It's better you can give border to it. write like this:

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

Check this http://jsfiddle.net/dgc4q/

于 2012-05-07T10:04:05.887 回答
1

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

I find that weird, but I just learned: Yes, it is, if you wrap a span inside.

html:

<a href='#'><span>Howdy Partner</span></a>

css (sass)

html
  font-size: 6em

a
  color: red

span  
  color: green 

enter image description here

little advantage over border-bottom-solution:

You are certainly not affecting base-line, line-height, margin collapse, spacing between lines... (depending on situtation, border-bottom could do that)

于 2017-12-21T16:07:08.180 回答