thead with one td (full width) and tbody with 2 columns (width not depending on thead)

19,127

Solution 1

<table>
  <thead>
     <tr><th colspan="2">longer Heading with a width of 100%</th></tr>
  </thead>
  <tbody>
     <tr><td>cell 1</td><td>cell 2 </td></tr>
      <tr><td>cell 3</td><td>cell 4 </td></tr>
 </tbody>

use of colspan will do the trick for you

Solution 2

This?

<th colspan="2">...</th>

Solution 3

It's easier than that: You just need a colspan on your th element.
Colspan defines, how many cells the element extends:

<table>
    <thead>
        <tr><th colspan="2">longer Heading with a width of 100%</th></tr>
    </thead>
    <tbody>
        <tr><td>cell 1</td><td>cell 2</tr>
        <tr><td>cell 3</td><td>cell 4</tr>
    </tbody>
</table>

See my Fiddle

Share:
19,127

Related videos on Youtube

user2625636
Author by

user2625636

Updated on June 04, 2022

Comments

  • user2625636
    user2625636 almost 2 years

    Okay, long title short story. I've got a table structured like this:

    <table>
    <thead>
    <tr><th>longer Heading with a width of 100%</th></tr>
    </thead>
    <tbody>
    <tr><td>cell 1</td><td>cell 2</tr>
    <tr><td>cell 3</td><td>cell 4</tr>
    </tbody>
    </table>
    

    And I'd like the th to be full width and not change the width of the table cells. I guess there's some CSS display property that would make this possible but I haven't found a working solution yet.