Html table tr inside td

后端 未结 9 2205
余生分开走
余生分开走 2020-12-01 02:41

I am trying to create a table in HTML. I have the following design to create. I had added a inside the but somehow the table

相关标签:
9条回答
  • 2020-12-01 03:05

    You must add a full table inside the td

        <table>
          <tr>
            <td>
              <table>
                <tr>
                  <td>
                    ...
                  </td>
                </tr>
              </table>
            </td>
          </tr>
        </table>

    0 讨论(0)
  • 2020-12-01 03:07

    You cannot put tr inside td. You can see the allowed content from MDN web docs documentation about td. The relevant information is in the permitted content section.

    Another way to achieve this is by using colspan and rowspan. Check this fiddle.

    HTML:

    <table width="100%">
     <tr>
      <td>Name 1</td>
      <td>Name 2</td>
      <td colspan="2">Name 3</td>
      <td>Name 4</td>
     </tr>
    
     <tr>
      <td rowspan="3">ITEM 1</td>
      <td rowspan="3">ITEM 2</td>
      <td>name1</td>
      <td>price1</td>
      <td rowspan="3">ITEM 4</td>
     </tr>
    
     <tr>
      <td>name2</td>
      <td>price2</td>
     </tr>
     <tr>
      <td>name3</td>
      <td>price3/td>
     </tr>
    </table>
    

    And some CSS:

    table {
        border-collapse: collapse       
    }
    
    td {
       border: 1px solid #000000
    }
    
    0 讨论(0)
  • 2020-12-01 03:07

    You can check this just use table inside table like this

    <!DOCTYPE html>
    <html>
    
    <head>
      <style>
        table,
        th,
        td {
          border: 1px solid black;
          border-collapse: collapse;
        }
      </style>
    </head>
    
    <body>
      <table style="width:100%">
        <tr>
          <th>ABC</th>
          <th>ABC</th>
          <th>ABC</th>
          <th>ABC</th>
        </tr>
        <tr>
          <td>Item1</td>
          <td>Item1</td>
          <td>
            <table style="width:100%">
              <tr>
                <td>name1</td>
                <td>price1</td>
              </tr>
              <tr>
                <td>name2</td>
                <td>price2</td>
              </tr>
              <tr>
                <td>name3</td>
                <td>price3</td>
              </tr>
            </table>
          </td>
          <td>item1</td>
        </tr>
        <tr>
          <td>A</td>
          <td>B</td>
          <td>C</td>
          <td>D</td>
        </tr>
        <tr>
          <td>E</td>
          <td>F</td>
          <td>G</td>
          <td>H</td>
        </tr>
        <tr>
          <td>E</td>
          <td>R</td>
          <td>T</td>
          <td>T</td>
        </tr>
      </table>
    </body>
    
    </html>

    0 讨论(0)
提交回复
热议问题