Advertisement
makispaiktis

Codecademy - Table Headings and Scope Attribute

Aug 13th, 2019 (edited)
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.24 KB | None | 0 0
  1. Table Headings
  2. Table data doesn’t make much sense without titles to describe what the data represents.
  3.  
  4. To add titles to rows and columns, you can use the table heading element: <th>.
  5.  
  6. The table heading element is used just like a table data element, except with a relevant title. Just like table data, a table heading must be placed within a table row.
  7.  
  8. <table>
  9.   <tr>
  10.     <th></th>
  11.     <th scope="col">Saturday</th>
  12.     <th scope="col">Sunday</th>
  13.   </tr>
  14.   <tr>
  15.     <th scope="row">Temperature</th>
  16.     <td>73</td>
  17.     <td>81</td>
  18.   </tr>
  19. </table>
  20. What happened in the code above?
  21.  
  22. First, a new row was added to hold the three headings: a blank heading, a Saturday heading, and a Sunday heading. The blank heading creates the extra table cell necessary to align the table headings correctly over the data they correspond to.
  23.  
  24. In the second row, one table heading was added as a row title: Temperature.
  25.  
  26. Note, also, the use of the scope attribute, which can take one of two values:
  27.  
  28. row - this value makes it clear that the heading is for a row.
  29. col - this value makes it clear that the heading is for a column.
  30. HTML code for tables may look a little strange at first, but analyzing it piece by piece helps make the code more understandable.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement