How are table headers supposed to be used?

I recently saw a code like this:

<tr> 
     <th> Some label: </th>
     <td> <input type="text" value=""/> </td>
     <th> Another label: </th>
     <td> <input type="text" value=""/> </td>
</tr>

I use table headers that are used as

<tr> 
     <th> Some label: </th>
     <th> Another label: </th>
</tr>
<tr>
     <td> <input type="text" value=""/> </td>
     <td> <input type="text" value=""/> </td>
</tr>

How should table headers be used? The first example above led me to some pretty funny formatting problems, and it seems like in example 1 <label>should be used instead <th>.

+3
source share
3 answers

None of them are correct. The title is used to represent the title of the table, and not as a mechanism for arranging form fields. As you mentioned, I would use <label>. Tables should be used to represent tabular data.

, , , <th> . , <thead> <tbody>:

<table>
   <thead>
      <tr>
         <th>Heading 1</th>
         <th>Heading 2</th>
      </tr>
   </thead>
   <tbody>
      <tr>
         <td>Row 1 Col 1 Data</td>
         <td>Row 1 Col 2 Data</td>
      </tr>
      <tr>
         <td>Row 2 Col 1 Data</td>
         <td>Row 2 Col 2 Data</td>
      </tr>
   </tbody>
</table>

, , .

, <tfoot> , .

+3

, th tr. , label. (, , -, , , .)

0

In the first example, the labels and input fields will be on the same line. This does not mean that it should be used <TH>. In the second example, you have the headers in their own line above the input fields. You definitely need to add <table>and </table>.

0
source

Source: https://habr.com/ru/post/1782340/


All Articles