空白下划线(也称为文本装饰下划线)通常用于在文本下方添加一条线,以突出显示文本或表示链接状态。在 CSS 中,可以通过 text-decoration
属性来实现这一效果。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS 空白下划线示例</title>
<style>
.underline {
text-decoration: underline;
}
.double-underline {
text-decoration: underline double;
}
.dotted-underline {
text-decoration: underline dotted;
}
</style>
</head>
<body>
<p class="underline">单线下划线示例</p>
<p class="double-underline">双线下划线示例</p>
<p class="dotted-underline">虚线下划线示例</p>
</body>
</html>
原因:下划线默认会覆盖文本的基线,导致文本看起来像是悬挂在下划线上方。
解决方法:
.underline {
text-decoration: underline;
text-decoration-skip-ink: auto;
}
解决方法:
.no-underline {
text-decoration: none;
}
解决方法:
.specific-text {
text-decoration: underline;
}
通过以上方法,可以有效地管理和控制 CSS 中的下划线效果,以满足不同的设计需求。
领取专属 10元无门槛券
手把手带您无忧上云