Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML table colgroup element not working?

I want different styles on each column of a table. I've read that you could do that by using <colgroup> or <col>, but I had no luck. I have an example here, and nothing seems to change. Am I doing something wrong? Will this work on xhtml?

I know I could add a "class" attribute on each <td>, but that seems weak.

like image 259
pleasedontbelong Avatar asked Sep 07 '10 12:09

pleasedontbelong


People also ask

Is Colgroup supported in HTML5?

Most of the attributes in HTML 4.01 <colgroup> are not supported in HTML5.

How does Colgroup work HTML?

The <colgroup> tag specifies a group of one or more columns in a table for formatting. The <colgroup> tag is useful for applying styles to entire columns, instead of repeating the styles for each cell, for each row.

What is Colgroup span in HTML?

Definition and Usage. The span attribute defines the number of columns a <colgroup> element should span. Tip: To define different properties to a column within a <colgroup> , use the <col> tag within the <colgroup> tag.


2 Answers

That's correct. While colgroup itself is supported by all browsers, this isn't true for the attributes of the inner col element. Of possible attributes, only width is supported on all browsers. But unlike CSS, <col width=""> only supports pixel and percentage widths.

Don't use it. Instead, create CSS classes and assign them to each td. Yes, it sucks.

EDIT Updated link above to page with better information

like image 109
Aaron Digulla Avatar answered Sep 20 '22 03:09

Aaron Digulla


Set your table-layout to auto instead of fixed...

table {table-layout: auto;} 

My personal site supports multiple themes and I see these kinds of differences all the time.

like image 33
John Avatar answered Sep 23 '22 03:09

John