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

HtmlCssBackground Color

Html Problem Overview


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

Html Solutions


Solution 1 - Html

table{border-collapse:collapse;}

Solution 2 - Html

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.

Solution 3 - Html

Try this:

    .rowhighlight > td { background: green;}

Solution 4 - Html

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; }

Solution 5 - Html

tr.rowhighlight td, tr.rowhighlight th{
    background-color:#f0f8ff;
}

Solution 6 - Html

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

Solution 7 - Html

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;}

Solution 8 - Html

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionH. FerrenceView Question on Stackoverflow
Solution 1 - HtmlJasperoView Answer on Stackoverflow
Solution 2 - HtmldlssoView Answer on Stackoverflow
Solution 3 - HtmlAtte VäätäinenView Answer on Stackoverflow
Solution 4 - HtmlBoltClockView Answer on Stackoverflow
Solution 5 - HtmlÁlvaro GonzálezView Answer on Stackoverflow
Solution 6 - HtmlT4NK3RView Answer on Stackoverflow
Solution 7 - HtmlGeert ImmerzeelView Answer on Stackoverflow
Solution 8 - Htmlwebgeek atlbikeView Answer on Stackoverflow