在CSS中,我们可以为文本设置各种样式,其中包括给字体加下划线和改变下划线的颜色。/ 给字体加下划线 / textdecoration: underline; / 改变下划线的颜色 / textdec...
在CSS中,我们可以为文本设置各种样式,其中包括给字体加下划线和改变下划线的颜色。
/* 给字体加下划线 */
text-decoration: underline;
/* 改变下划线的颜色 */
text-decoration-color: red; 使用text-decoration: underline;可以为文本添加下划线效果。此属性可以设置为以下值:
none:不加下划线underline:添加下划线overline:添加上划线line-through:添加删除线blink:添加闪烁如果需要为下划线改变颜色,我们可以使用text-decoration-color属性。此属性默认值为currentcolor,表示继承文本的颜色,也可以设置为具体的颜色值。
/* 将下划线的颜色设置为红色 */
text-decoration-color: red; 需要注意的是,text-decoration-color属性需要与text-decoration属性一起使用才有效果。
下面是一个例子,我们为一段文字添加下划线,并将下划线的颜色设置为红色:
<p style="text-decoration: underline;
text-decoration-color: red;">
这是一段有下划线的文字
</p> 运行结果如下:
这是一段有下划线的文字
通过这篇文章,相信大家已经学会了如何在CSS中为字体添加下划线,并改变下划线的颜色。