Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html table header rowspan to center headers

I have a table like this:

<table border="1">
<thead>        
    <tr>
        <th colspan="2">Items</th>
        <th colspan="2">Type</th>
        <th colspan="4">Values</th>
        <th colspan="2">Date</th>
    </tr>        
    <tr>
        <th colspan="2"></th>
        <th colspan="2"></th>
        <th colspan="2">Before</th>
        <th colspan="2">After</th>
        <th colspan="2"></th>
    </tr>
</thead>
<tbody></tbody>

In the header of the table, I would like to have the headers Items, Type and Date to be centered vertically. I tried using rowspan="2" on these headers, but that didn't work. Any idea please?

like image 622
user765368 Avatar asked Oct 15 '25 10:10

user765368


1 Answers

When using rowspan, you have to not add the columns in the next rows (or as much rows as the rowspan number minus one).

Your demo, updated:

<table border="1">
    <thead>
        <tr>
            <th rowspan="2">Items</th>
            <th rowspan="2">Type</th>
            <th colspan="4">Values</th>
            <th rowspan="2">Date</th>
        </tr>
        <tr>
            <th colspan="2">Before</th>
            <th colspan="2">After</th>
        </tr>
    </thead>
    <tbody></tbody>
</table>

Note: If you remove the Before and After colspan, your Values colspan can be just 2.

like image 58
acdcjunior Avatar answered Oct 16 '25 22:10

acdcjunior



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!