Quantcast
Channel: Using text-align center in colgroup - Stack Overflow
Viewing all articles
Browse latest Browse all 5

Answer by DisgruntledGoat for Using text-align center in colgroup

$
0
0

See a similar question: Why is styling table columns not allowed?

You are only allowed to set border, background, width and visibility properties, due to the fact that cells aren't direct descendents of columns, only of rows.

There are a few solutions. The simplest is to add a class to each cell in the column. Unfortunately that means more HTML, but it shouldn't bee a problem if you're generating tables from a database, etc.

Another solution for modern browsers (i.e., not Internet Explorer 6) is to use some pseudo classes. tr > td:first-child will select the first cell in a row. Opera, Safari, Chrome and Firefox 3.5 also support the :nth-child(n) selector so you can target specific columns.

You could also use td+td to select from the second column onwards (it actually means "select all td elements that have one td element to its left). td+td+td selects from the third column - you can continue in this fashion, overriding properties. Honestly though, it's not great code.


Viewing all articles
Browse latest Browse all 5

Trending Articles