Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple rows in td

Stores <td> contain table with mulitple rows. A store can have mulitple stores (rows).

See Example: https://jsfiddle.net/ak3wtkak/1/

The width of Stores and Quantity (<th>) columns should be same for mulitple rows on the second table. How to fix this or what is alternative approach?

enter image description here

<table border="1" width="100%">
  <thead>
    <tr>
      <th style="width:300px">Product</th>
      <th>Barcode</th>
      <th>Stores</th>
      <th class="middle">Quantity</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
      Item 1
      </td>
      <td>12345</td>
      <td colspan="3">
        <table border="1" width="100%">
          <tbody>
            <tr>
              <td>Store Name 1</td>
              <td class="middle">4</td>
            </tr>
            <tr>
              <td>Store Name 2</td>
              <td class="middle">4</td>
            </tr>
            <tr>
              <td>Store Name 3</td>
              <td class="middle">4</td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>
  </tbody>
</table>
like image 554
I'll-Be-Back Avatar asked Mar 22 '17 10:03

I'll-Be-Back


People also ask

How do I put multiple lines in one cell in HTML?

The rowspan attribute in HTML specifies the number of rows a cell should span. That is if a row spans two rows, it means it will take up the space of two rows in that table. It allows the single table cell to span the height of more than one cell or row.

How can I add multiple rows in one column in HTML?

You can merge two or more table cells in a column using the colspan attribute in a <td> HTML tag (table data). To merge two or more row cells, use the rowspan attribute.

Can we use Rowspan in TD?

The HTML rowspan attribute define the number of rows a cell of a table should span in an HTML document. It can only be applied on td or th HTML element.

How do you split a TD with two lines?

In the table, click the cell that you want to split. Click the Layout tab. In the Merge group, click Split Cells. In the Split Cells dialog, select the number of columns and rows that you want and then click OK.


1 Answers

You have to use rowspan. Make the first 2 rows with rowspan of 3.

<table border="1" width="100%">
  <thead>
    <tr>
      <th style="width:300px">Product</th>
      <th>Barcode</th>
      <th>Stores</th>
      <th class="middle">Quantity</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td rowspan="3">Item 1</td>
      <td rowspan="3">12345</td>
      <td>Store Name 1</td>
      <td>4</td>
    </tr>
    <tr>
      <td>Store Name 2</td>
      <td>4</td>
    </tr>
    <tr>
      <td>Store Name 3</td>
      <td>4</td>
    </tr>
  </tbody>
</table>
like image 155
Reza San Avatar answered Sep 27 '22 16:09

Reza San