Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table Column Formatting

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>
like image 415
Andy Avatar asked Oct 01 '08 14:10

Andy


People also ask

How do I format a column in a table in Excel?

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.

How do I format columns in a Word table?

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....

What is table formatting in Word?

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.

How do I format a column?

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.


1 Answers

As far as I know, you can only format the following using CSS on the <col> element:

  • background-color
  • border
  • width
  • visibility

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.

like image 126
Bill Avatar answered Nov 23 '22 16:11

Bill