CSS中设置下划线的颜色可以通过text-decoration-color属性来实现。
span {
text-decoration: underline;
text-decoration-color: red;
} 上述代码中,我们为span元素设置了下划线,并且将下划线的颜色设置为红色。
如果想让下划线的颜色和文本颜色一样,可以使用currentColor关键字。
span {
text-decoration: underline;
text-decoration-color: currentColor;
color: blue;
} 在上述代码中,我们让下划线的颜色等于文本颜色,即让下划线和文字都是蓝色。
需要注意的是,text-decoration-color属性不支持IE浏览器,但可以使用border-bottom代替下划线的效果,并且设置border-color属性来实现颜色的改变。