Reputation: 464
I have a cell in a table like this:
<td><b>Grand Total</b></td>
I need to give it a line under the text "Grand Total". I used text-decoration: underline;
. It worked well, but I need to change the color and thickness of the underline. I used text-decoration-color: red;
to add color but it doesn't work. How can I solve this problem?
Upvotes: 9
Views: 71614
Reputation: 91
Usually I use these three CSS properties to style the underline
text-decoration-thickness: 3px;
text-decoration-color: red;
text-underline-offset: 5px;
Upvotes: 4
Reputation: 141
The best approach is to use the text-decoration-thickness
css property. Here is the link to the documentation. A simple code sample would look something like:
text-decoration: underline solid black 2px;
The 2px
here is the text-decoration-thickness
or rather the width of the underline.
Upvotes: 10
Reputation: 797
If you target your 'b', you can use a background gradient which will allow you to adjust the thickness of the line and the line's vertical placement.
eg.
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;
}
Upvotes: 2
Reputation: 127
td {
position: relative;
}
td::after {
content: '';
position: absolute;
width: 30%;
display: block;
height: 5px;
background-color: red;
bottom: -5px;
}
To control the width, you just change the width from 100% to whatever value you wish.
Upvotes: 0
Reputation: 4391
Use pseudo elements like :before
and :after
to control the length of the underline as well
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>
Upvotes: 4
Reputation: 5401
From here
td {
color: red;
text-decoration: underline;
}
span {
color: black;
text-decoration: none;
}
<table>
<tr>
<td><b><span>Grand Total</span></b></td>
</tr>
</table>
Upvotes: 2
Reputation: 1596
You should give class or id to your specific line, like:
HTML:
<td><b id="total">Grand Total</b></td>
CSS:
#total {
border-bottom: 1px solid red;
padding: 0 0 4px;
}
Upvotes: 2
Reputation: 7079
You cannot modify the width of underline
tag. Instead go for Border-bottom
approach and change it's properties as required.
.underline {
border-bottom: 5px solid red;
}
<table>
<tr>
<td><b class="underline">Grand Total</b></td>
</tr>
</table>
Upvotes: 5
Reputation: 627
use border-bottom
define color cording like this
b {
border-bottom: 1px solid red;
padding: 0 0 4px;
}
<td><b>Grand Total</b></td>
Upvotes: 11