I made a table with a color on the top row and there are some white spaces in between the columns. Is there any way I could get rid of them and fill them in with my color? This is my output: Output This is my code:
<table style="width:100%;">
<tr style="background-color:#820000;color:white;font-family:sans-serif;">
<td style="width:6%">
Item #
</td>
<td style="width:75%">
Description
</td>
<td style="width:8%">
Quantity
</td>
<td style="width:7%">
Price
</td>
<td style="width:4%">
Cost
</td>
</tr>
</table>
3
Answers
You can achieve this with the
border-collapse: collapse
rule on the<table>
.I recommend overhauling this to make it more dynamic:
To eliminate the white spaces between the columns in your table and ensure that the background color extends across the entire row, you can adjust your table’s CSS. Specifically, you want to remove any padding and margin from the table cells. Here’s how you can modify your code:
By default browser stylesheet, table element has border-spacing that gives each
<td>
space.To get rid of the space, you can easily add the table element
border-spacing:0;