Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I have one HTML table header be over two table columns? Like merge and center in Excel?

I want to have one table header be centered over two table columns side by side. Is this possible?

like image 833
Lizza Avatar asked Jan 25 '12 00:01

Lizza


People also ask

How do I make two columns under one heading in HTML?

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.

How do I combine table headers in HTML?

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.

Can a table have multiple headers HTML?

You can have different headers for different rows.


2 Answers

<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.

like image 108
SpoonNZ Avatar answered Sep 20 '22 12:09

SpoonNZ


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> 
like image 41
Travis J Avatar answered Sep 20 '22 12:09

Travis J