要为文本添加下划线效果,可以使用CSS的text-decoration属性。通过设置text-decoration: underline;,可以在文本下方添加下划线。
以下是示例代码:
.element {
text-decoration: underline;
}
在上述示例中,将text-decoration属性应用于.element选择器,从而为相应的HTML元素添加下划线效果。
除了underline值,text-decoration属性还可以使用其他值来实现不同的文本装饰效果,如删除线(line-through)、上划线(overline)等。
如果要仅对链接文本添加下划线,可以使用:link和:visited伪类选择器来针对未访问和已访问的链接设置下划线样式。
a:link {
text-decoration: underline;
}a:visited {
text-decoration: underline;
}
在上述示例中,通过为a:link和a:visited选择器设置text-decoration属性,为链接文本添加下划线效果。
通过使用text-decoration属性,可以根据需要为文本添加下划线或其他文本装饰效果。