How to get css background color on <tr> tag to span entire row
Asked Answered
C

8

62

I have tried everything I can think of in css in order to get a background color to span an entire table row (<tr> tag) But I keep getting a white border around each cell.

CSS (excerpt):

/*alternating row*/
table, tr, td, th {margin:0;border:0;padding:0;}
tr.rowhighlight {background-color:#f0f8ff;margin:0;border:0;padding:0;}

HTML (excerpt):

<tr class="rowhighlight"><td>A</td><td>B</td><td>C</td></tr>

It just does not want to cooperate. Thanks for helping...

Continuance answered 15/4, 2011 at 18:18 Comment(0)
C
64
table{border-collapse:collapse;}
Connie answered 15/4, 2011 at 18:24 Comment(4)
table border-collapse doesn't do it Firefox 4Continuance
Works fine for me in FF4. Try using Reset CSS. There must be something overriding. Or let us see your code in jsfiddle.Connie
add <table id="standings" style="border-collapse:collapse"> Worked for me in Firebug on your site.Connie
Wow, that's so weird. It works inline but not through the css. The styles in the css are the last set defined. Well, at least it works. Thanks Jaspero.Continuance
H
12

I prefer to use border-spacing as it allows more flexibility. For instance, you could do

table {
  border-spacing: 0 2px;
}

Which would only collapse the vertical borders and leave the horizontal ones in tact, which is what it sounds like the OP was actually looking for.

Note that border-spacing: 0 is not the same as border-collapse: collapse. You will need to use the latter if you want to add your own border to a tr as seen here.

Hispanic answered 5/7, 2016 at 22:0 Comment(0)
C
7

Try this:

    .rowhighlight > td { background: green;}
Cataclysmic answered 8/4, 2016 at 11:0 Comment(0)
C
5

Removing the borders should make the background color paint without any gaps between the cells. If you look carefully at this jsFiddle, you should see that the light blue color stretches across the row with no white gaps.

If all else fails, try this:

table { border-collapse: collapse; }
Congruence answered 15/4, 2011 at 18:20 Comment(6)
table border-collapse did not do it eitherContinuance
looks fine in jsFiddle -- just doesn't look right in Firefox 4Continuance
Looks fine for me in Firefox 4. Maybe you've got an inheritance/specificity problem, or a doctype issue (unlikely).Packhorse
I'm using FF4 and the jsFiddle example has no gaps. Perhaps you have some other code interfering with it? I suggest downloading Firebug and seeing what rules are actually being used.Body
I do use firebug. my css is the last set of cssContinuance
js fiddle has it's own style sheet that applies table { border-collapse: collapse; border-spacing: 0; } which makes it never show the gaps (even if you remove all the css formatting except the row colourDeettadeeyn
T
3
tr.rowhighlight td, tr.rowhighlight th{
    background-color:#f0f8ff;
}
Tenderhearted answered 15/4, 2011 at 18:21 Comment(0)
W
1

Firefox and Chrome are different
Chrome ignores the TR's background-color
Example: http://jsfiddle.net/T4NK3R/9SE4p/

<tr style="background-color:#F00">
     <td style="background-color:#FFF; border-radius:20px">
</tr>  

In FF the TD gets red corners, in Chrome not

Winfrid answered 29/11, 2013 at 7:46 Comment(0)
C
0

Have you tried setting the spacing to zero?

/*alternating row*/
table, tr, td, th {margin:0;border:0;padding:0;spacing:0;}
tr.rowhighlight {background-color:#f0f8ff;margin:0;border:0;padding:0;spacing:0;}
Copestone answered 15/4, 2011 at 18:28 Comment(2)
Did you mean border-spacing?Congruence
Spacing is not a valid css style, but border-spacing is. I tried border-spacing and that did not do it.Continuance
C
0

This worked for me, even within a div:

      div.cntrblk tr:hover td {
        line-height: 150%;
        background-color: rgb(255,0,0);
        font-weight: bold;
        font-size: 150%;
        border: 0;
      }

It selected the entire row, but I'd like it to not do the header, haven't looked at that yet. It also partially fixed the fonts that wouldn't scale-up with the hover??? Apparently you to have apply settings to the cell not the row, but select all the component cells with the tr:hover. On to tracking down the in-consistent font scaling problem. Sweet that CSS will do this.

Conyers answered 31/3, 2015 at 23:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.