I want to have one table header be centered over two table columns side by side. Is this possible?
If a header spans two or more columns, use a <colgroup> element instead of that number of <col> elements, and the number of columns spanned is noted in the span attribute. Also, the value of the scope attribute in the first-level headers is set to colgroup so that it is associated with the entire group of columns.
To merge table columns in HTML use the colspan attribute in <td> tag. With this, merge cells with each other. For example, if your table is having 4 rows and 4 columns, then with colspan attribute, you can easily merge 2 or even 3 of the table cells.
You can have different headers for different rows.
<th colspan="2">. This .</th>
To extrapolate a bit...
<table> <thead> <tr> <th>Single Column</th> <th colspan="2">Double Column</th> </tr> </thead> <tbody> <tr> <td>Column One</td> <td>Column Two</td> <td>Column Three</td> </tr> </tbody> </table>
That should give you enough to work from.
If you only have 2 columns then I would suggest using <caption>
. Otherwise, use colspan as suggested in other answers.
<table> <caption>This will span all columns.</caption> <tr><td>column one</td><td>column two</td></tr> </table>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With