Underlining an html anchor with different color

2019-06-17 07:33发布

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 ?

标签: html css anchor
4条回答
贪生不怕死
2楼-- · 2019-06-17 08:19

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.

查看更多
神经病院院长
3楼-- · 2019-06-17 08:26

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/

查看更多
爷、活的狠高调
4楼-- · 2019-06-17 08:27

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;
}
查看更多
萌系小妹纸
5楼-- · 2019-06-17 08:28

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

查看更多
登录 后发表回答