Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create tables from column data instead of row data in HTML?

According to this article at W3 Schools, one can create a basic table in HTML like this:

<table border="1">     <tr>         <td>row 1, cell 1</td>         <td>row 1, cell 2</td>     </tr>     <tr>         <td>row 2, cell 1</td>         <td>row 2, cell 2</td>     </tr> </table> 

From above, it appears that one enters data by rows.

I have a situation where I need to enter all of the data by columns. Is something like this possible?

<table border="1">     <tc>         <td>row 1, cell 1</td>         <td>row 2, cell 1</td>     </tc>     <tc>         <td>row 1, cell 2</td>         <td>row 2, cell 2</td>     </tc> </table> 
like image 340
Village Avatar asked Apr 17 '13 23:04

Village


People also ask

How do I make a column table in HTML?

Creating Tables in HTML Inside the <table> element, you can use the <tr> elements to create rows, and to create columns inside a row you can use the <td> elements. You can also define a cell as a header for a group of table cells using the <th> element.

How do you put data into a table in HTML?

The insertRow() method creates an empty <tr> element and adds it to a table. The insertRow() method inserts the new row(s) at the specified index in the table. Note: A <tr> element must contain one or more <th> or <td> elements.

How do you create tables using HTML?

To create table in HTML, use the <table> tag. A table consist of rows and columns, which can be set using one or more <tr>, <th>, and <td> elements. A table row is defined by the <tr> tag. To set table header, use the <th> tag.


1 Answers

In modern browsers you can achieve this by redefining the TR and TD tags behavior in CSS. Given the HTML in your question attach the next CSS style:

table {  	display: table;  }  table tr {  	display: table-cell;  }  table tr td {  	display: block;  }
<table border="1">      <tr>          <td>row 1, cell 1</td>          <td>row 2, cell 1</td>      </tr>      <tr>          <td>row 1, cell 2</td>          <td>row 2, cell 2</td>      </tr>  </table>
like image 171
Istvan Avatar answered Sep 20 '22 18:09

Istvan