Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include 2 columns under one column header in html table?

I want to create an html table, which should look like this:

enter image description here

I know I will have to use colspan/rowspan attributes, but how? Can anyone help?

I have tried following :

<table>
<thead>
<tr>
<th>Evaluation</th><th>Approval</th>
<th colspan="2" >Points</th>
<th>Total</th>
<th>Date</th><th>Award Amount</th><th>Last Modified By</th>
</tr>
</thead>
<tbody>
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
</tbody>
</table>

but is is giving me result as:

enter image description here

Clearly, I need to subheader in 3rd header (Points), how to achieve this?

like image 738
hitesh.gawhade Avatar asked Feb 25 '13 09:02

hitesh.gawhade


People also ask

How do I add two columns to one column 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 HTML tables have two rows as headings th?

HTML tables can have headers for each column or row, or for many columns/rows.

How do I make two rows in one column in HTML?

You can merge two or more table cells in a column using the colspan attribute in a <td> HTML tag (table data). To merge two or more row cells, use the rowspan attribute.


2 Answers

Like this:

<table>
    <thead>
        <tr>
            <th rowspan="2">Evaluation</th>
            <th rowspan="2">Approval</th>
            <th colspan="2">Points</th> // <- note colspan here
            <th rowspan="2">Total</th>
            <th rowspan="2">Date</th>
            <th rowspan="2">Award Amount</th>
            <th rowspan="2">Last Modified By</th>
        </tr>
        <tr>
            <th>Tangible</th>
            <th>Intangible</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Al/GL</td>
            <td>Select</td>
            <td>col1</td>
            <td>col2</td>
            <td>col3</td>
            <td>col4</td>
            <td>col5</td>
            <td>col6</td>
        </tr>
    </tbody>
</table>
like image 181
Luke Robertson Avatar answered Nov 04 '22 18:11

Luke Robertson


this is the table fullstructure

<table>
    <tr>
        <td rowspan="2"></td>
        <td rowspan="2"></td>
        <td colspan="2"></td>
        <td rowspan="2"></td>
        <td rowspan="2"></td>
        <td rowspan="2"></td>
    </tr>
    <tr>
        <td></td>
        <td></td>
    </tr>
</table>

thanks...

like image 26
felix Antony Avatar answered Nov 04 '22 19:11

felix Antony