在 CSS 中,您可以使用文本装饰(text-decoration)属性来为文字添加下划线。
下面是一个简单的示例代码:
.text-underline {
text-decoration: underline;
在上面的代码中,我们为一个类名为 "text-underline" 的元素添加了下划线。您可以将这个类名应用于任何需要添加下划线的文本元素上。
如果您想要更改下划线的颜色,可以使用文本装饰线颜色(text-decoration-color)属性。例如:
.text-underline {
text-decoration: underline;
text-decoration-color: red;
在上面的代码中,我们为下划线指定了红色颜色。
如果您只想在鼠标悬停时添加下划线,可以使用 :hover 伪类。例如:
.text-underline:hover {
text-decoration: underline;
在上面的代码中,当鼠标悬停在具有 "text-underline" 类名的元素上时,会添加下划线。
希望这个回答能够帮助您!