Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add border-bottom to table row <tr>

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.

like image 496
Sangram Nandkhile Avatar asked Apr 06 '12 08:04

Sangram Nandkhile


People also ask

How do I add a border to a row in a table?

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).

Can we give border to TR?

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.

How do I add a border to a TR tag in HTML?

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.


2 Answers

Add border-collapse:collapse to your table rule:

table {      border-collapse: collapse;  } 

Example

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

like image 114
Nathan Manousos Avatar answered Sep 22 '22 11:09

Nathan Manousos


I had a problem like this before. I don't think tr can take a border styling directly. My workaround was to style the tds in the row:

<tr class="border_bottom"> 

CSS:

tr.border_bottom td {   border-bottom: 1px solid black; } 
like image 23
tsherif Avatar answered Sep 21 '22 11:09

tsherif