Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html table - by rows or columns

do all browsers support html table by columns first.

i know you can do:

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

but can you build up a table by columns first? Is there anything wrong with doing cols first?

like image 819
leora Avatar asked Aug 16 '09 22:08

leora


People also ask

How do I make rows and columns in an HTML table?

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.

Can an HTML table have different columns in different rows?

Cells within HTML tables can span multiple rows and multiple columns. The cell default is one row and one column. However, with the ROWSPAN attribute a cell can span more than one row, and with the COLSPAN attribute a cell can span more than one column.


3 Answers

That is not how the HTML standard is. You make your table, then you make a row, and then your columns. There is some additional stuff for headers, bodies, etc. But the standard (and only supported method) is by row and not by column.

like image 61
TheTXI Avatar answered Sep 24 '22 13:09

TheTXI


According to the W3C HTML4 Table Specifications:

Furthermore, authors may declare column properties at the start of a table definition (via the COLGROUP and COL elements) in a way that enables user agents to render the table incrementally rather than having to wait for all the table data to arrive before rendering.

This important note on column properties does not change the functional structure of the table but does allow for flexibility in both styling a table as well as semantically describing its data. Specifically, associated row and column data provides benefits to screenreaders.

That stated your table is still structured by row and then column. The colgroup and col elements are used prior to the actual table structure appearing before thead.

like image 24
ahsteele Avatar answered Sep 24 '22 13:09

ahsteele


You need to think in terms of a relational DOM (Document Object Model).

 Table -- Parent
       TR --- Child
            TD ---- Child

Its true tables do have a cells collection, but cells can never be direct decedents of a table. a cell must be encompassed in a row, and a row must be a child of a table element.

If you're looking for another approach, try using XHTML, you can nest divs and spans to replace tables. But I personally prefer good old HTML 4.

like image 23
JL. Avatar answered Sep 23 '22 13:09

JL.