CSS 中哪个属性用于为文本添加下划线、上划线和删除线?
在 CSS 中,"text-decoration"属性用于为文本添加下划线、上划线和删除线。
给文本添加下划线意味着在文本下方画一条线,给文本添加上划线意味着在文本上方画一条线。删除文本意味着在文本上画一条线,表示文本已被擦除。
在本教程中,我们将学习如何使用 CSS 属性 text-decoration 的不同值来为文本设置不同的样式。
语法
text-decoration: style decoration color thick;
值
样式– 表示装饰线的样式,例如实线、虚线、波浪线等。
装饰- 可以使用"下划线"、"上划线"和"穿过线"值来装饰文本。
颜色– 设置装饰线的颜色。
粗细– 用于设置装饰线的粗细。
示例
在下面的示例中,我们使用了 CSS 属性"text-decoration"来装饰文本。我们设置了"实线"线条样式、红色"下划线"装饰和 5px 粗细,用户可以在输出中观察到。
<html>
<head>
<style>
.text {
font-size: 1.2rem;
text-decoration: solid underline red 5px;
}
</style>
</head>
<body>
<h3> Setting the underline to the text using the 'text-decoration' property in CSS </h3>
<div class = "text">
This is a text with an underline.
</div>
</body>
</html>
示例
在下面的示例中,我们使用蓝色上划线的方式修饰了文本。在输出中,用户可以观察到文本上方的蓝线。
<html>
<head>
<style>
.text {
font-size: 1.2rem;
text-decoration: wavy overline blue 5px;
}
</style>
</head>
<body>
<h3> Setting the <i> overline to the text </i> using the 'textdecoration' property in CSS </h3>
<div class = "text">
This is a text with an overline.
</div>
</body>
</html>
示例
在此示例中,我们使用了 CSS 属性"text-decoration"和"line-through"来删除文本。在输出中,用户可以观察到文本上方的删除线。这样,我们就可以在不删除文本的情况下显示文本中的错误。
<html>
<head>
<style>
.text {
font-size: 2rem;
text-decoration: dotted line-through green 5px;
}
</style>
</head>
<body>
<h3> Setting the <i> strickthrough to the text </i> using the 'textdecoration' property in CSS </h3>
<div class = "text">
This is a text with a strikethrough.
</div>
</body>
</html>
示例
在本例中,我们创建了三个不同的 div 元素,并分别包含不同的文本。我们对每个 div 元素的文本使用了不同的装饰样式。在输出中,用户可以观察到"下划线"、"上划线"和"删除线"文本装饰样式之间的区别。
<html>
<head>
<style>
.underline {
color: grey;
text-decoration: solid underline yellow 2px;
font-size: 1.5rem;
}
.overline {
text-decoration: solid overline yellow 3px;
font-size: 1.5rem;
}
.strikethrough {
text-decoration: solid line-through yellow 2px;
font-size: 1.5rem;
}
</style>
</head>
<body>
<h3> Setting the strikethrough, underline, and overline to the text using the 'text-decoration' property in CSS </h3>
<div class = "underline"> underline </div>
<div class = "overline"> overline </div>
<div class = "strikethrough"> strike through </div>
</body>
</html>
总结
本教程教你如何使用 CSS 属性"text-decoration"来修饰文本。用户可以根据需要使用不同的值来修饰文本。
相关文章
有用资源
css 参考教程 - 该教程包含有关 css 的更多信息:https://www.cainiaomax.com/css/

