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>
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.
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.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With