search

Home  >  Q&A  >  body text

Are there any other solutions to the problem of colspan="1.5" not working?

This is the table I need I can get the first and second rows easily, but when I try to make the third row good, I'm breaking the second row.

I tried using width attribute and colspan but nothing worked.

<table border="1px" width="100%">
        <tr>
            <td colspan="6">Cell 1</td>
        </tr>
        <tr >
            <td colspan="3">Cell 2</td> 
            <td colspan="3" >Cell 3</td>
        </tr>
        <tr>
            <td colspan="2">Cell 4</td> 
            <td colspan="2">Cell 5</td>            
            <td colspan="2">Cell 6</td> 
        </tr>
    </table>

P粉368878176P粉368878176267 days ago576

reply all(1)I'll reply

  • P粉262073176

    P粉2620731762024-03-31 00:42:12

    <table> will fit its content by default, so each column does not need to be equal width. So manually assign equal column widths by assigning table-layout:fixed to <table> and then assign each width to the first < ; in <thead> to allocate equal width to each column. tr> or missing allocated width for <td> of the first <tr> (of course td or th also works as a selector), see example below.

    table {
      table-layout: fixed;
    }
    
    td {
      width: 16.5%;
      text-align: center;
    }
    I
    II III
    IV V VI

    reply
    0
  • Cancelreply