Because margin
is ignored on tr
, I usually use a workaround, by setting a transparent border-bottom
or border-top
and setting the background-clip
property to padding-box
so the background-color
does not get painted underneath the border.
table {
border-collapse: collapse; /* [1] */
}
th, td {
border-bottom: 5px solid transparent; /* [2] */
background-color: gold; /* [3] */
background-clip: padding-box; /* [4] */
}
- Makes sure cells share a common border, but is completely optional. The solution works without it.
- The
5px
value represents the margin that you want to achieve
- Sets the
background-color
of your row/cell
- Makes sure the
background
get not painted underneath the border
see a demo here: http://codepen.io/meodai/pen/MJMVNR?editors=1100
background-clip
is supported in all modern browser. (And IE9+)
Alternatively you could use a border-spacing
. But this will not work with border-collapse
set to collapse
.