12
HTML Tables Presenting data in rows and columns

07 html tables

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: 07 html tables

HTML Tables Presenting data in rows and columns

Page 2: 07 html tables

Sometimes data is best presented in tables �  Rows �  Columns

�  Cells �  With headers and footers

Page 3: 07 html tables

Tables are simple to create, but verbose

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

Page 4: 07 html tables

A simple table has just rows and columns <table>!<tr>!<td>Andy Bernard</td><td>$9,963.49</td><td>$5,976.20</td><td>$7,920.45</td><td>$23,860.14</td>!</tr>!<tr>!<td>Pam Halpert</td><td>$8,258.87</td><td>$6,188.07</td><td>$9,365.33</td><td>$23,812.27</td>!</tr>!<tr>!<td>Stanley Hudson</td><td>$5,587.17</td><td>$9,493.05</td><td>$5,911.82</td><td>$20,992.04</td>!</tr>!…!</table>!

Page 5: 07 html tables

Table headers and footers � Header <thead>!<tr>! <th></th><th>January</th><th>February</th><th>March</th><th>Total</th>!</tr>!</thead>!

�  Footer <tfoot>!<tr><td></td><td>$46,515.48</td><td>$45,703.88</td><td>$47,796.08</td><td>$140,015.43</td></tr>!</tfoot>!

Page 6: 07 html tables

We can have data that spans across two or more rows or columns

<tr>! <th colspan="5">First Quarter Sales</th>!</tr>!

Page 7: 07 html tables

Tables are for data, not layout

Page 8: 07 html tables

Stylin' tables can and should be done using CSS

Much more on styling tables soon.

Page 9: 07 html tables

Applying overall styles <link rel="stylesheet" type="text/css" href="site.css" />!

table{!

!font-family: Arial, Sans-Serif;!

!font-size: 12px;!

!background: #fff;!

!margin: 45px;!

!width: 480px;!

}!

th{!

!font-size: 14px;!

!color: #039;!

!padding: 10px 8px;!

!border-bottom: 2px solid;!

}!

td{!

!color: #669;!

!padding: 9px 8px 0px 8px;!

}!

Page 10: 07 html tables

Alternating rows tr:nth-child(odd) {! background: #eef; !}!

Page 11: 07 html tables

Hovering over a row: tr:hover tbody tr:hover td!{! color: #339;! background: #d0dafd;!}!

Page 12: 07 html tables

Conclusion

� HTML tables are for data, not for layout � They can have headers and footers � Cells can span rows and columns � We can make tables look fantastic by styling

them through CSS