Table colspan span all columns regardless of # of columns

12,743

Colspan can't be done with CSS. It's structural rather than stylistic so it's pure HTML.

No you can't specify "all but one" as a colspan. The best you can do is colspan="0", which will span the remaining columns in the column group but to take advantage the <colgroup> at the top will need to know the number of columns anyway and be define statically.

See Tables in the HTML spec:

colspan = number [CN]

This attribute specifies the number of columns spanned by the current cell. The default value of this attribute is one ("1"). The value zero ("0") means that the cell spans all columns from the current column to the last column of the column group (COLGROUP) in which the cell is defined.

But basically this just kicks the can down the street and I don't know what the browser support is like so it doesn't necessarily buy you anything.

You'll either need to know the number of columns when you generate the HTML or use Javascript.

Share:
12,743
jamone
Author by

jamone

iOS and macOS app developer.

Updated on June 04, 2022

Comments

  • jamone
    jamone almost 2 years

    I'm creating a table in an asp.net code behind dynamically, and I want to have a footer row that only has 2 cells. The first should span all the columns in the table-1. Is there some way other then keeping track of the # of columns in the table manually for me to set the colspan to be # of all the columns in the table-1?

    Preferably a HTML or CSS solution?