I would like to know if is possible to prevent double borders in a tr > td
element. If I use border:1px solid #DDD
then the first element will have all borders and then the second one too but because the first has a border-right and the second has a border-left then the borders are double and the same happens for the second tr where first has border-bottom and second has border-top. Any tips? I see this post but won't work for me because is for DIV and I'm using tables.
You can remove the space between the different borders by using the CSS border-collapse property. You can apply this property against the HTML table element. When you apply this against the table element, you'll notice that the table border simply disappears, or "collapses".
Add a border-left and border-top to the parent. Add border-right and border-bottom to each of the children.
To avoid having double borders like in the example above, set the CSS border-collapse property to collapse .
Not directly: adding a border to a tr isn't allowed. But you can target the first and last cell, give those a left/right border respectively. Then on each cell put a top border and a bottom border on each td element.
Start with:
border-collapse:collapse;
and then tune as necessary. Using the :first-child
and :last-child
pseudo selectors can be used to modify default styling on one end.
Instead of putting borders on the cells, set a background color on the table itself to the color you want the borders to be, then space the cells by 1px:
HTML:
<table>
<tr>
<td>One</td>
<td>Two</td>
<td>Three</td>
</tr>
<tr>
<td>Four</td>
<td>Five</td>
<td>Six</td>
</tr>
</table>
CSS:
table {
background: #ccc;
border-spacing: 1px;
}
td {
background: #fff;
padding: 5px;
}
That will give you this:
Note that you have to set a background color on the cells themselves, too, otherwise the background color of the table will show through.
You're looking for border-collapse
The border-collapse CSS property selects a table's border model. This has a big influence on the look and style of the table cells.
Values are as such.
border-collapse: collapse | separate | inherit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With