I'm trying to format a column in a <table/>
using a <col/>
element. I can set background-color
, width
, etc., but can't set the font-weight
. Why doesn't it work?
<table>
<col style="font-weight:bold; background-color:#CCC;">
<col>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table>
Reading through this as I was attempting to style a table such that the first column would be bold text and the the other four columns would be normal text. Using col tag seemed like the way to go but while I could set the widths of the columns with the width attribute the font-weight: bold wouldn't work Thanks for pointing me in the direction of the solution. By styling all the td elements
td {font-weight: bold;}
and then using an adjacent sibling selector to select columns 2-5 and style them back to normaltd + td {font-weight: normal;}
Voila, alls good :)Your best bet is to apply your styling directly to the
<td>
tags. I've never used the<col>
tag, but most browsers let you apply formatting at the<table>
and<td>
/<th>
level, but not at an intermediate level. For example if you havethen this CSS won't work
but this will
Also: I assume your code above is just for demonstration purposes and you're not actually going to apply styles inline.
As far as I know, you can only format the following using CSS on the
<col>
element:This page has more info.
Herb is right - it's better to style the
<td>
's directly. What I do is the following:This won't work in IE however.
You might have just needed this:
A
col
tag must be inside of acolgroup
tag, This may be something to do with the problem.Have you tried applying the style through a CSS class?
The following appears to work:
Reference for the col element