22

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?

2
  • 2
    Well described in w3.org/TR/html4/struct/tables.html
    – twk
    Commented Aug 16, 2009 at 22:11
  • Here is a similar reference for HTML5 - w3.org/TR/2014/REC-html5-20141028/tabular-data.html It would be nice to have both options because sometimes you have the most closely related data in the same column rather than row, and that would be fine for small tables because you don't want horizontal scrolling. But it's not an option unless you use another method than just a basic table.
    – Michael K
    Commented Nov 1, 2023 at 16:37

6 Answers 6

16

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.

8

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.

5

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.

0

HTML tables have tbody (and thead and tfoot) elements which contain table row elements which contain table data cell and table header cell elements.

You can't build a table by providing a each full column in turn. Only each full row in turn.

0

Well you should really used HTML standard, the reasons is because messing with a tables columns and rows can make the code tricky to deal with. Just stick with standard HTML.

0

To print columns first, do it as a table: <tr><td>'s in tables within a table.

See the following example:

// begin parent table here: tr and td 

    <table>    
        <tr><td>  //first row (in a sense) of cols
        <tr><td>  //first row (in a sense) of cols
        <tr><td>  //first row (in a sense) of cols
    </table>

// end parent td start new td

    <table>
        <tr><td>  //second row (in a sense) of cols
        <tr><td>  //second row (in a sense) of cols
        <tr><td>  //second row (in a sense) of cols
    </table>

// end parent td and tr and end table
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.