I have a table of 3 by 3. I need a way to add a border for the bottom of every row tr
and give it a specific color.
First I tried the direct way, i.e.:
<tr style="border-bottom:1pt solid black;">
But that didn't work. So I added CSS like this:
tr { border-bottom: 1pt solid black; }
That still didn't work.
I would prefer to use CSS because then I don't need to add a style
attribute to every row. I haven't added a border
attribute to the <table>
. I hope that that is not affecting my CSS.
To add a border to your table, you need to define the <style> of your table. Remember to add borders also for <th> and <td> tags to have a complete table. Set the border-collapse property as well (if you don't define the border-collapse, it will use border-collapse: separate by default).
Not directly: adding a border to a tr isn't allowed. But you can target the first and last cell, give those a left/right border respectively. Then on each cell put a top border and a bottom border on each td element.
Borders can be added to rows of table by adding border to <td> and <th> elements [This is basically a CSS trick to achieve (hack!) that as borders cannot be added to <tr> and <tbody> elements of table]. Add following styles to your CSS to get borders around rows or headers or table cells.
Add border-collapse:collapse
to your table rule:
table { border-collapse: collapse; }
table { border-collapse: collapse; } tr { border-bottom: 1pt solid black; }
<table> <tr><td>A1</td><td>B1</td><td>C1</td></tr> <tr><td>A2</td><td>B2</td><td>C2</td></tr> <tr><td>A2</td><td>B2</td><td>C2</td></tr> </table>
Link
I had a problem like this before. I don't think tr
can take a border styling directly. My workaround was to style the td
s in the row:
<tr class="border_bottom">
CSS:
tr.border_bottom td { border-bottom: 1px solid black; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With