Cellspacing and cellpadding alternative in css
Filed in CSS, Development on Apr.22, 2009
Frankly speaking, I’ve been always using <table cellspacing="0" cellpadding="0" border="1">
It was not a question for me until some time whether these attributes of <table>
tag have its css alternative. The solution has been found rather quickly and the use is very simple.
table {
padding: 0;
border-spacing: 0;
border-collapse: collapse;
}
table tr td, table tr th {
border: 1px solid black;
}
border-collapse: collapse
is used to make border line single between two cells. By default border-collapse is set to "separate" in browsers, i.e. both borders are shown (so, the line is doubled)
This trick makes your xhtml code a little less in size.