Tables, bordercolor w3 validation errors, and CSS
May 1st, 2007 by SteveIf you are trying to validate your HTML with Dreamweaver or w3.org, you may have noticed errors stating there is no such attribute as “bordercolor”. Once again, CSS saves the day. The quick solution is to add a style class then insert the tables in a span:
.tbblue table, .tbblue td { border: 1px solid #0000ff; background-color: #000000; color: #00FFFF;}
<span class="tbblue"> <table width="60%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>=1=</td><td>=2=</td>
</tr>
<tr>
<td>=3=</td><td>=4=</td>
</tr>
</table></span>
Should result in this 2×2 table:
| =1= | =2= |
| =3= | =4= |
Another option does not even require the use of CSS; Just give the table a background color and cellspacing a size equal to your desired border, then give the table cells a different background color. If you put the table in a span like I did in the first example, you can avoid having to define the background color (bgcolor=”#000000″) in every table cell. Instead, add something like this to your style sheet: .tbblue td {background-color: #000000;}
Here’s the code for the non-CSS version:
<table bgcolor="#66ccff" border="0" cellpadding="0" cellspacing="1" width="50">
<tr>
<td bgcolor="#000000">=1=</td>
<td bgcolor="#000000">=2=</td>
</tr>
<tr>
<td bgcolor="#000000">=3=</td>
<td bgcolor="#000000">=4=</td>
</tr>
</table>
| =1= | =2= |
| =3= | =4= |
October 2nd, 2008 at 3:28 pm
Passed, senks author
November 30th, 2008 at 4:19 am
Nice post u have here
Added to my RSS reader
July 22nd, 2010 at 2:57 pm
You can also but the class directly on your table, or for a one-shot bordercolour (generally not recommended) use the style attribute.
Using attributes for styling is generally a no-no, unless there really is no other way.