6

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?

curveball
  • 4,320
  • 15
  • 39
  • 49
Jibin
  • 424
  • 2
  • 4
  • 15

9 Answers9

10

use border-bottom define color cording like this

b {
    border-bottom: 1px solid red;
    padding: 0 0 4px;
}
<td><b>Grand Total</b></td>
lalit bhakuni
  • 607
  • 5
  • 15
5

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>
Deepak Yadav
  • 6,804
  • 5
  • 31
  • 49
4

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>
Dan Philip Bejoy
  • 4,321
  • 1
  • 18
  • 33
4

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.

Geeky
  • 81
  • 2
  • supported in all but FF on Android and IE https://caniuse.com/?search=text-decoration-thickness – Fanky Apr 07 '22 at 20:36
3

Usually I use these three CSS properties to style the underline

To set the thickness of the underline

text-decoration-thickness: 3px;

To set the color of the underline

text-decoration-color: red;

To offset the underline

text-underline-offset: 5px;

2

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;
}
NARGIS PARWEEN
  • 1,489
  • 3
  • 16
  • 26
2

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>
Community
  • 1
  • 1
Carl Binalla
  • 5,393
  • 5
  • 27
  • 46
1

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;
}
Reece
  • 777
  • 5
  • 22
  • 42
0
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.

Edward Bella
  • 127
  • 10