【发布时间】:2018-02-09 02:37:09
【问题描述】:
我想给文字装饰上色。我从w3schools得到了一个教程
并尝试了这个
text-decoration: underline;
text-decoration-color: #dddddd;
但它不起作用。这无效吗?有没有其他方法可以给下划线上色?
【问题讨论】:
标签: css
我想给文字装饰上色。我从w3schools得到了一个教程
并尝试了这个
text-decoration: underline;
text-decoration-color: #dddddd;
但它不起作用。这无效吗?有没有其他方法可以给下划线上色?
【问题讨论】:
标签: css
text-decoration-color 拥有minimal browser support
相反,您可以使用像跨度这样的东西来重新着色您的文本:
p {
color: red; /* colour of underline */
text-decoration: underline;
}
span {
color: black; /* original colour of p */
}
<p><span>underline is red, text is black</span></p>
【讨论】:
您的代码可能会影响另一个类
p {
text-decoration: underline;
text-decoration-color: red!important;
}
<p>test</p>
【讨论】:
更新:它适用于带有 -webkit- 前缀的 Safari 和 Safari iOS!
p {
text-decoration: underline;
text-decoration-color: red;
-webkit-text-decoration-color: red;
}
<p>test</p>
【讨论】:
以下方法添加到字符串中的行下。
1) 您可以使用 text-decoration 在字符串底部添加下划线,如下所示。请尝试以这种方式添加您的 CSS。
以下演示很适合我。
<style type="text/css">
.underline
{
text-decoration: underline;
text-decoration-color: red;
/*color: blue;
border-bottom: 1px solid red;*/
}
</style>
<span class="underline">hello world</span>
2)如果尝试在第一步中归档,您可以尝试第二种方式在字符串底部设置边框
<style type="text/css">
.underline
{
/*text-decoration: underline;
text-decoration-color: red;*/
color: blue;
border-bottom: 1px solid red;
}
</style>
<span class="underline">hello world</span>
【讨论】: