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

2

8

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;
}
Chouest answered 29/8, 2011 at 17:18 Comment(1)
See the edit to my answer @oooIced
I
13

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

Iced answered 29/8, 2011 at 17:22 Comment(2)
the issue is that if i use: border-collapse:collapse then the border-radius styling doesn't work anymore.Chouest
Putting border-collapse:collapse on the table worked for meDieter
P
1

Some versions of some browsers don't take kindly to setting border styles on tr elements.

You can always set them on their tds instead.

.underRow td {
    border-bottom: 1px solid #7a26b9;
}

If there is border spacing you may need to collapse your table borders using border-collapse: collapse;.

Polestar answered 29/8, 2011 at 17:20 Comment(4)
i updated the question a bit around the issue with using the class attribute on the tds. Is there anyway around this so i have a straight line below the row.Chouest
Can I see the rest of your CSS for your table? As well as the table itself. Maybe put it on jsFiddle.Polestar
i updated the question with the rest of the css which is on the table.Chouest
the issue now is that if i use: border-collapse:collapse then the border-radius styling doesn't work anymoreChouest

© 2022 - 2024 — McMap. All rights reserved.