This is my code:
<html>
<style>
.left-info
{
font-size:14px;
font-family:Tahoma, Helvetica, sans-serif;
color:#1A5B71;
font-weight:bold;
text-align:right;
}
.right-info
{
font-size:14px;
font-family:Tahoma, Helvetica, sans-serif;
color:#FFFFFF;
font-weight:bold;
text-align:left;
}
</style>
<body>
<table border="1">
<colgroup>
<col class="left-info" />
<col class="right-info" />
</colgroup>
<tr>
<td>3476896</td>
<td>My first HTML</td>
</tr>
<tr>
<td>5869207</td>
<td>My first CSS</td>
</tr>
</table>
</body>
</html>
But, it is showing simple table. Need help !!
Look here
http://www.w3.org/TR/CSS21/tables.html#columns
You can only set
border
,background
,width
andvisibility
withcol
sedit
jQuery solution
With this little jQuery snippet you can copy all the class names from the
col
tags to the correspondingtd
tagsIt works even with colspan in both
col
andtd
tags as well as with nested tables.Example here as jsfiddle
JavaScript
Although the answer given here is about a year old at this point, I thought I'd just point out that you can easily do this with very simple CSS
Instead of trying to give the class to every td in its column, you can simply target them like this:
Using JavaScript to complete this task is complete overkill
I've written a small jQuery script for this that applies the class to every
th
andtd
element in thecolspan
s table.Try it here
JavaScript:
The script isn't complicated, but here are the steps:
colgroup
col
s havetr
in the same tablecol
to 0tr
(th
s andtd
s)col
col
by itscolspan
attribute or 1 if it isn't present, so that at the next iteration, the script will know what class to selectcolgroup
altogether, because you could, for example, have a background that doens't have an opacity of 1, which would result in yourth
s andtd
s having a background with the wrong opacity.I cache
$(this)
a couple of times, because it is faster to cache jQuery objects than calling$()
everytime you want to select an element.