Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table vertical header?

Tags:

How can I make the table header appear on the left side of the table as a column instead on the top as a row? I have this markup:

<table>   <thead>     <tr>       <th>a</th>       <th>b</th>     </tr>   </thead>   <tbody>     <tr>       <td>1</td>       <td>2</td>     </tr>   </tbody> </table> 
like image 873
Richard Knop Avatar asked Apr 27 '11 07:04

Richard Knop


People also ask

How do you make a table vertical in HTML?

The trick is to use display: inline-block; on the table rows and white-space: nowrap; on the table body.

How do I create a horizontal header in a table?

Tables in HTML can have horizontal as well as the vertical header. For the horizontal header, you need to set all <th> inside a single <tr> tag i.e. row, that will be the topmost.

How can you give column headers in a table in HTML?

The <th> tag defines a header cell in an HTML table. An HTML table has two kinds of cells: Header cells - contains header information (created with the <th> element) Data cells - contains data (created with the <td> element)


1 Answers

Just use <th> as the first element in the row. Then add the scope attribute, which has no visual impact, but you could use it e.g. in CSS.

<table>   <tbody>     <tr>       <th scope="row">A</th>       <td>b</td>     </tr>     <tr>       <th scope="row">C</th>       <td>d</td>     </tr>   </tbody> </table> 

See also http://www.w3.org/TR/WCAG20-TECHS/H63

like image 157
jakov Avatar answered Sep 28 '22 18:09

jakov