Search code examples
htmlhtml-table

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


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.


Solution

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