Mr.Glaurung Mr.Glaurung - 6 months ago 9
HTML Question

Enforce CSS class to all elements in a table

I have a css which works perfectly:

.border
{
border: 1px solid black;
font-size: 12px;
padding: 2px;
vertical-align: top;
text-align: left;
}

.clean
{
border: none;
font-size: 14px;
}


No problem. But to create a table with border I will have to do:

<table class="border">
<tr>
<td class="border"></td>
<td class="border"></td>
</tr>


I find this brutally tedious. Isn't there a way to go:

<table class="border">
<tr><td></td><td></td></tr>


with the same result as the above?
I want an "excel-like" square grid, not only a border around the table (second example).

Pls help.

Answer

You don't need to apply the class inside all your tds. Just use like this:

table.border,table.border td{//Applying border in table html
   border: 1px solid black;
}