I have a variable number of table rows (n), and I would like the border bottom to apply to rows 0..(n-1)
how do I do that?
noBorder td to make the border go away for all the <td> s that are inside of <tr> s with the noBorder class by assigning border: 0 . Note that you do not need to provide the unit (i.e. px ) if you set something to 0 as it does not matter anyway. Zero is just zero.
If you want to add a border only to the bottom of the table row, you can apply the CSS border-bottom property to <td> elements that are placed within a <tr> tag.
You have two options: (1) adding a specialized class in the HTML to the last row; or (2) using the :last-child
pseudo class in your CSS.
If you can apply classes to your HTML, you can add a specialized class to the final row. If your markup is being generated by a server-side script (eg. a PHP script), you will need to edit that script to add similar markup.
HTML:
<table> <tr> <td> </td> </tr> <tr> <td> </td> </tr> <tr class="last"> <td> </td> </tr> </table>
CSS:
table { border-collapse:collapse; } tr { border-bottom: 1px solid #000; } tr.last { border-bottom: none; }
The alternative is to use the :last-child
CSS pseudo class. Using the :last-child
class doesn't require any changes to the HTML and so may be a better choice if you aren't able to change the HTML. The CSS is almost identical to the above:
CSS:
table { border-collapse:collapse; } tr { border-bottom: 1px solid #000; } tr:last-child { border-bottom: none; }
The drawback of this approach is that versions of Internet Explorer before 9 don't support the :last-child
pseudo class.
I know this is an old question, but it's worth mentioning that now with CSS3 all you have to do is us the not()
selector in your CSS, like this:
tr:not(:last-child) { border-bottom: 1px solid #E3E3E3; }
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