Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 835
H. Ferrence Avatar asked Apr 15 '11 18:04

H. Ferrence


People also ask

How do I change the background color of a TR tag?

HTML | <tr> bgcolor Attributecolor_name: It sets the background color by using the color name. For example “red”. hex_number: It sets the background color by using the color hex code.

How do you add a background Colour for all section tags?

How to Add Background Color in HTML. To add background color in HTML, use the CSS background-color property. Set it to the color name or code you want and place it inside a style attribute. Then add this style attribute to an HTML element, like a table, heading, div, or span tag.

How do you change the background color of an entire table?

In HTML, table background color is defined using Cascading Style Sheets (CSS). Specifically, you use the background-color property to define background color. You can apply this property against the whole table, a row, or a single cell. Below are some examples of applying background color to a table in HTML.


2 Answers

table{border-collapse:collapse;} 
like image 114
Jaspero Avatar answered Sep 30 '22 16:09

Jaspero


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.

like image 34
dlsso Avatar answered Sep 30 '22 15:09

dlsso