text-decoration-color无效主因是未启用装饰线,需配合text-decoration-line或简写属性使用,推荐text-decoration: underline solid color;并注意浏览器兼容性及样式覆盖问题。
在使用 CSS 的 text-decoration-color 设置文字装饰颜色时,如果发现样式无效,可能是由于语法错误、浏览器兼容性或未正确启用相关属性导致的。这个属性用于设置下划线(underline)、上划线(overline)或删除线(line-through)的颜色,但它必须配合 text-decoration-line 一起使用,否则可能不会生效。
例如:
.example {
text-decoration-line: underline;
text-decoration-color: red;
}
/* 或者更简洁的写法 */
.example {
text-decoration: underline;
text-decoration-color: red;
}
.highlight {
text-decoration: underline solid #00bcd4;
}
其中 #00bcd4 就是装饰线的颜色。这种写法更可靠,也更容易维护。
如果需要兼容老浏览器,可考虑用 border-bottom 模拟下划线:
.fallback {
color: #000;
border-bottom: 1px solid red;
text-decoration: none;
}

基本上就这些。只要确保装饰线已开启、语法正确、浏览器支持,并排除样式覆盖,text-decoration-color 就能正常工作。不复杂但容易忽略细节。