A little CSS trick for tables
<tr><th>Date</th><th>OrderID</th></tr>
<cfoutput query="registeredOrders">
<tr><td>#DateFormat(orderDate, "d.mmm yyyy")#</td><td>#objectID#</td></tr>
</cfoutput>
</table>
So far so good. Now I wanted to make some borders around the cells. What I've previously been doing is to set a cellspacing of 1 pixel on my table, make a background color for the table (the same color as I want for borders, and then another background color for th and td elements. Something like this:
table {background-color: #000000;}
th {background-color: #CAE4FF;}
td {background-color: #FFFFFF;}
</style>
<table cellspacing="1">
<tr><th>Date</th><th>OrderID</th></tr>
<cfoutput query="registeredOrders">
<tr><td>#DateFormat(orderDate, "d.mmm yyyy")#</td><td>#objectID#</td></tr>
</cfoutput>
</table>
Now that works. There's no invalid code. It's easy to read and manipulate. However, it felt wrong to use a table background color to make a border color. I thought there had to be a better/cleaner way of doing this with CSS only. And so together with my colleague we started looking (using The Google*) and he found a simple css attribute neither of us have used before (and we use a lot of css).
Better to show than to tell. Here's the code how it looks now:
table {border-collapse: collapse;}
th {background-color: #CAE4FF;}
th, td {border: solid 1px #000000;}
</style>
<table>
<tr><th>Date</th><th>OrderID</th></tr>
<cfoutput query="registeredOrders">
<tr><td>#DateFormat(orderDate, "d.mmm yyyy")#</td><td>#objectID#</td></tr>
</cfoutput>
</table>
So we did not save much code right away. But now all aspects of the formating is controlled by the css. And when dealing with many tables using the same css we will have saved code, and eased the managability.


IIRC, the MM coding guidlines from a few years ago stated that you should always have at least border, cellspacing and cellpadding in your tables.
Wonder if it's changed now?
Taking it further, I've been able to border the table differently than the cell borders for finished look. Nice.
There seems to be a bug in Mozilla where the cell border is drawn over the table border when the thickness is 1px for both. If you widen the table border to 2px it then is drawn over the cell border. (cell and table borders were differentiated by color in my tinkering)