Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any reason you can't put a border around a <tr> in an html table using CSS

I have a table and I have a tr with a class set to "underRow".

In CSS I have:

.underRow {
 border-bottom-color: #7a26b9;
 border-bottom-style: solid;
 border-bottom-width: 1px;
}

but the row border doesn't seem to be changing at all. If I move the class attribute down to the td's it works fine (but the issue is that I get a space in the middle where the padding is between the cells. I want to avoid this space and have one straight line below the row.

Is there anything wrong with putting CSS border attributes on a row (tr) element?

Here is the rest of the CSS on this table for reference:

.quantityTable {
    border-radius: 5px 5px 5px 5px;
    background-color: #d6b4E1;
    padding: 5px;
    margin-bottom: 5px;
    width: 100%;
    border-width: 2px;
    border-color: #7a26b9;
    border-style: solid;
}
like image 241
leora Avatar asked Aug 29 '11 17:08

leora


People also ask

Can I add border to TR tag?

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.

Can TR have border?

How do you put a border on TR? 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 a TR have border radius?

To add border radius to a table row tr , you have to specifically target the first table data td on the row and the last.

Why HTML table does not have borders?

If you've set the shorthand border property in CSS and the border is not showing, the most likely issue is that you did not define the border style. While the border-width and border-color property values can be omitted, the border-style property must be defined. Otherwise, it will not render.


1 Answers

No it should work.

See this: http://jsfiddle.net/jasongennaro/qCzrg/

Perhaps you need to collapse your borders with

border-collapse:collapse

Or maybe other styles for the TD is overriding

Can you show some more code.

As per your edit:

(but the issue is that i get a space in the middle where the padding is between the cells. I want to avoid this space and have one straight line below the row.

Sounds like you definitely need border-collapse

You should add it to the style of the table.

Here's a bit more about it: http://www.the-art-of-web.com/css/bordercollapse/

EDIT 2

Based on the new code and the following comment:

the issue is that if i use: border-collapse:collapse then the border-radius styling doesn't work anymore

I am guessing you want something like this

.quantityTable{
    border-radius: 15px 15px 15px 15px;
    background-color: #d6b4E1;
    margin-bottom: 5px;
    width: 100%;    
}

.underRow{
    border-bottom-color: #7a26b9;
    border-bottom-style: solid;
    border-bottom-width: 1px;
}

.underRow:last-child{
    border-bottom:none;
}

.underRow td{
    padding: 15px;  
}

Example: http://jsfiddle.net/jasongennaro/qCzrg/1/

NOTE

  1. I made the radius bigger so you could see it easier.

  2. I also removed the border from the table itself

like image 118
Jason Gennaro Avatar answered Sep 20 '22 12:09

Jason Gennaro