在 CSS 中,text-decoration 属性用于控制文本的装饰效果,例如下划线、删除线等。该属性可以应用于任何文本元素,如段落、标题、链接等。
值
text-decoration 属性可以接受以下值:
none:默认值,文本没有任何装饰效果。underline:添加下划线。overline:添加上划线。line-through:添加删除线。blink:使文本闪烁。
示例代码
// www.javascriptcn.com code example
/* 添加下划线 */
.underline {
text-decoration: underline;
}
/* 添加上划线 */
.overline {
text-decoration: overline;
}
/* 添加删除线 */
.line-through {
text-decoration: line-through;
}
/* 使文本闪烁 */
.blink {
text-decoration: blink;
}组合值
text-decoration 属性还可以接受多个值,用空格分隔,可以同时应用多种装饰效果。
/* 同时添加下划线和删除线 */
.underline-line-through {
text-decoration: underline line-through;
}注意事项
- 不同浏览器对
text-decoration的支持可能有所不同,特别是对blink值的支持,因此在使用时需要注意兼容性问题。 - 可以通过
text-decoration-color和text-decoration-style属性进一步定制文本装饰效果的颜色和样式。
以上是关于 CSS 属性 text-decoration 的介绍,希望能够帮助您更好地掌握文本装饰效果的应用。