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>
Select any cell within the table, or range of cells you want to format as a table. On the Home tab, click Format as Table. Click the table style that you want to use.
Click the Page Layout tab, and then select Columns.... Choose the format of your columns. You can select a preset, automatically formatted number of columns with equal spacing by clicking One, Two, Three, or Four. You can also manually select the number, width, and spacing of the columns by clicking More columns....
After you create a table, you can format the entire table by using Table Styles. By resting your pointer over each of the preformatted table styles, you can preview what the table will look like. Click in the table that you want to format. Under Table Tools, click the Design tab.
To open the Format column panel, select a column heading, select Column settings from the menu, and then select Format this column. The Format column panel appears.
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:
<style type="text/css">
#mytable tr > td:first-child { color: red;} /* first column */
#mytable tr > td:first-child + td { color: green;} /* second column */
#mytable tr > td:first-child + td + td { color: blue;} /* third column */
</style>
</head>
<body>
<table id="mytable">
<tr>
<td>text 1</td>
<td>text 2</td>
<td>text 3</td>
</tr>
<tr>
<td>text 4</td>
<td>text 5</td>
<td>text 6</td>
</tr>
</table>
This won't work in IE however.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With