Styling a whole table column

Discussion in 'CSS' started by Echilon, Jan 8, 2009.

  1. #1
    I'm sure I read a while ago about a way to style a whole column in a table by adding scope="col" and using a certain CSS selector, but I can't remember what it was. Is there any other way to apply a style to a whole column without setting a class for each cell?
     
    Echilon, Jan 8, 2009 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #2
    Scope is one way, the COL and COLGROUP tags is another, you can also use the nth-child psuedoselectors or sibling selectors.... There's only one problem with that...

    Firefux and other gecko based browsers pretty much ignore COL outright (see the DECADE old bugzilla #915 for details) and mangles scope for much the same reason, while nth-child and sibling selectors are unsupported in IE6 and unreliable in IE7.

    Which is why I STILL end up resorting to a class on each damned cell 9 out of ten times - nobody actually has the damned implementation WORKING properly!

    Oh, and while scope in SOME browsers will copy the styling information down a column or across a row, that is not actually what it means NOR does the actual specification say it should do that.
     
    deathshadow, Jan 8, 2009 IP
  3. Adriana41

    Adriana41 Peon

    Messages:
    18
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I always end up styling each column individually with classes *sigh*, nothing else seems to work properly.
     
    Adriana41, Jan 10, 2009 IP
  4. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #4
    We're pretty much stuck for trivial tables. For others, programmed markup is preferred, when possible. Javascript can walk the DOM, setting the attribute, but is subject to being disabled. My preference is to use a server side templating engine such as Smarty.
    <table summary="">
       {foreach from=$data item="entry"}
            <tr>
                <td class="something">{$entry.xxx}</td>        
                <td>{$entry.yyy}</td>        
            </tr>
    
        {foreachelse}
            <tr>
                <td colspan="2">No records</td>
            </tr>
        {/foreach}
    </table>
    Code (markup):
    Not as elegant as having the columns styleable, but a lot less drudge than typing, copy and paste, or even defining a macro to do it.

    cheers,

    gary
     
    kk5st, Jan 10, 2009 IP