Andy Andy - 1 year ago 107
CSS Question

Table Column Formatting

I'm trying to format a column in a

using a
element. I can set
, etc., but can't set the
. Why doesn't it work?

<col style="font-weight:bold; background-color:#CCC;">

Answer Source

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 */
   <table id="mytable">
      <td>text 1</td>
      <td>text 2</td>
      <td>text 3</td>
      <td>text 4</td>
      <td>text 5</td>
      <td>text 6</td>

This won't work in IE however.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download