homepage Welcome to WebmasterWorld Guest from 54.211.80.155
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / CSS
Forum Library, Charter, Moderator: open

CSS Forum

    
Attributes for entire table column?
enchant




msg:3292519
 12:40 pm on Mar 25, 2007 (gmt 0)

Often, when I'm putting a table together, I need all items in a specific column to have a certain attribute, and I was wondering if there was a better way than to specify it in every table cell in that column.

 

Ingolemo




msg:3292692
 5:26 pm on Mar 25, 2007 (gmt 0)

If you need to apply styles to a whole column, you could use the col element. Unfortunately, most implementations don't consistently recognise it.

<table>
<col>
<col style="background:red;">
<tbody>
<tr><td>1</td><td>2</td></tr>
<tr><td>3</td><td>4</td></tr>
</tbody>
</table>

rebelde




msg:3292887
 11:03 pm on Mar 25, 2007 (gmt 0)

That example looked good in IE7 and Firefox. I was surprised. I had looked into this a while back and it didn't work. Does anybody know specifically how well this works these days?

SuzyUK




msg:3293043
 6:39 am on Mar 26, 2007 (gmt 0)

It works fine, BUT the properties that you can apply to <col> are limited, not by support issues but by its nature.

You can only apply border, background, width & visibility properties to the col & colgroup elements. - ref: W3C recs [w3.org]

IE will allow you to do more, text-align is one, though not sure what all it does 'support', it's this that leads to x-browser support confusion at times?

- the 4 properties above are supported quite consistently

[edited by: SuzyUK at 6:40 am (utc) on Mar. 26, 2007]

Ingolemo




msg:3293505
 5:28 pm on Mar 26, 2007 (gmt 0)

Thanks SuzyUK, that's what I meant to imply, but I worded it badly.

enchant




msg:3295232
 11:33 am on Mar 28, 2007 (gmt 0)

> You can only apply border, background, width & visibility properties

I was looking for attributes such as text-align (e.g. for a column of numbers) or BOLD or font-family, etc.

Achernar




msg:3295265
 12:08 pm on Mar 28, 2007 (gmt 0)

In gecko (and probably IE7) you can use this syntax:

tr td:first-child + td {
background-color: green;
color: white;
width: 50px;
}

This style will apply to the second column, and only to it (add a third column to your test to verify).

firstreflex




msg:3295438
 2:57 pm on Mar 28, 2007 (gmt 0)

> You can only apply border, background, width & visibility properties

I don't think border works consistently

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / CSS
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved