Monday, September 29, 2008

Cellspacing and Cellpadding With CSS

In HTML, a <table> can have a couple attributes added to it: cellspacing and cellpadding, and these attributes are valid code. Unfortunately, these have default values so that writing
<table>
is basically the same as
<table cellpadding="1" cellspacing="2">

This becomes a problem when you do not want this additional space and cannot change the HTML, as cellpadding and cellspacing are not CSS attributes. There is still a way to get around this in CSS with the following code:
table {
border-collapse: collapse;
}

table td {
padding: 0
}

No comments: