I have a cell in a table like this:
<td><b>Grand Total</b></td>
我需要在“Grand Total”文本下面添加一条线。我使用了
text-decoration: underline;
,它运行良好,但我需要更改下划线的颜色和粗细。我尝试使用text-decoration-color: red;
添加颜色,但它不起作用。请问如何解决这个问题?使用border-bottom
来定义颜色码:
b {
border-bottom: 1px solid red;
padding: 0 0 4px;
}
<td><b>Grand Total</b></td>
text-decoration-thickness
CSS 属性。这里是指向文档的链接:链接。一个简单的代码示例如下所示:text-decoration: underline solid black 2px;
2px
是text-decoration-thickness
,也就是下划线的宽度。您无法修改underline
标签的宽度。相反,可以采用border-bottom
方法并根据需要更改其属性。
.underline {
border-bottom: 5px solid red;
}
<table>
<tr>
<td><b class="underline">Grand Total</b></td>
</tr>
</table>
:before
和:after
来控制下划线的长度。
td {
position: relative;
}
td:after {
content: '';
position: absolute;
width: 100%;
display: block;
height: 5px;
background-color: red;
bottom: -5px;
}
<table>
<tbody>
<tr>
<td><b>Grand Total</b></td>
</tr>
</tbody>
</table>
通常我使用这三个CSS属性来样式化下划线
text-decoration-thickness: 3px;
text-decoration-color: 红色;
text-underline-offset: 5px;
<td><b id="total">Grand Total</b></td>
#total {
border-bottom: 1px solid red;
padding: 0 0 4px;
}
来自这里
td {
color: red;
text-decoration: underline;
}
span {
color: black;
text-decoration: none;
}
<table>
<tr>
<td><b><span>Grand Total</span></b></td>
</tr>
</table>
b {
background-image: linear-gradient(to bottom, #fdb514 50%, transparent 50%);
background-position: 0px 0.9em;
background-repeat: repeat-x;
background-size: 1px 15px;
display: inline;
}
td {
position: relative;
}
td::after {
content: '';
position: absolute;
width: 30%;
display: block;
height: 5px;
background-color: red;
bottom: -5px;
}
要控制宽度,只需将宽度从100%更改为您希望的任何值即可。