Sie sind auf Seite 1von 10

Topic 6 HTML Tables Designing and Developing a Website

V1.0 Visuals Handout Page 1


Designingand Developing a
NCC Education Limited V1.0
Designing and Developing a
Website
Topic 6:
HTML Tables
HTML Tables Topic 6 - 6.2
Scope and Coverage
This topic will cover:
The structure of HTML tables
Column and row spanning
CSS and tables
NCC Education Limited V1.0
CSS and tables
Accessibility and tables
Tables as a page layout devices
HTML Tables Topic 6 - 6.3
Learning Outcomes
By the end of this topic, students will be able to:
Create HTML pages that structure tabular data
Describe techniques for making HTML tables
accessible to users with visual disabilities
NCC Education Limited V1.0
accessible to users with visual disabilities
Style HTML tables using Cascading Style Sheet
properties
Explain the disadvantages of using HTML tables
for page layout
Topic 6 HTML Tables Designing and Developing a Website
V1.0 Visuals Handout Page 2
HTML Tables Topic 6 - 6.4
Table Structure - 1
<table>
<tr>
<td>Stage</td><td>Winner</td>
</tr>
<tr>
<td>Paris to Lyon</td><td>Maurice Garin</td>
</tr>
NCC Education Limited V1.0
HTML elements can be used to describe tabular data
This is a very simple HTML table
</tr>
</table>
HTML Tables Topic 6 - 6.5
Table Structure - 2
<table>
<tr>
<td>Stage</td><td>Winner</td>
</tr>
<tr>
<td>Paris to Lyon</td><td>Maurice Garin</td>
</tr>
NCC Education Limited V1.0
The <table>element defines the start and end of
the table
</tr>
</table>
HTML Tables Topic 6 - 6.6
Table Structure - 3
<table>
<tr>
<td>Stage</td><td>Winner</td>
</tr>
<tr>
<td>Paris to Lyon</td><td>Maurice Garin</td>
</tr>
NCC Education Limited V1.0
The <tr>element defines the start and end of a
row in the table
</tr>
</table>
Topic 6 HTML Tables Designing and Developing a Website
V1.0 Visuals Handout Page 3
HTML Tables Topic 6 - 6.7
Table Structure - 4
<table>
<tr>
<td>Stage</td><td>Winner</td>
</tr>
<tr>
<td>Paris to Lyon</td><td>Maurice Garin</td>
</tr>
NCC Education Limited V1.0
The <td>element defines a table cell
</tr>
</table>
HTML Tables Topic 6 - 6.8
<table>
<tr>
<td>Stage</td><td>Distance</td><td>Stage Winner</td><td>Overall Leader</td>
</tr>
<tr>
<td>Paris to Lyon</td><td>467km</td><td>Maurice Garin</td><td>Maurice Garin</td>
</tr>
<tr>
<td>Lyon to Marseille</td><td>374km</td><td>Hippolyte Aucouturier</td><td>Maurice
Garin</td>
Table Structure - 5
NCC Education Limited V1.0
</tr>
<tr>
<td>Marseille to Toulouse</td><td>423km</td><td>Hippolyte Aucouturier</td><td>Maurice
Garin</td>
</tr>
</table>
We can define many rows and columns
Add more <tr>and <td>elements
HTML Tables Topic 6 - 6.9
Table Structure - 6
NCC Education Limited V1.0
Topic 6 HTML Tables Designing and Developing a Website
V1.0 Visuals Handout Page 4
HTML Tables Topic 6 - 6.10
<table>
<tr>
<td>Stage</td><td>Distance</td><td>Stage Winner</td><td>Overall
Leader</td>
</tr>
<tr>
<td>Paris to Lyon</td><td>467km</td><td colspan=" 2" >Maurice Garin</td>
</tr>
<tr>
The colspan Attribute - 1
NCC Education Limited V1.0
<tr>
<td>Lyon to Marseille</td><td>374km</td><td>Hippolyte
Aucouturier</td><td>Maurice Garin</td>
</tr>
<tr>
<td>Marseille to Toulouse</td><td>423km</td><td>Hippolyte
Aucouturier</td><td>Maurice Garin</td>
</tr>
</table>
HTML Tables Topic 6 - 6.11
The colspan Attribute - 2
<td colspan="2">Maurice Garin</td>
NCC Education Limited V1.0
The colspan attribute can be used to stretch a
table cell across multiple columns.
HTML Tables Topic 6 - 6.12
<table>
<tr>
<td>Stage</td><td>Distance</td><td>Stage Winner</td><td>Overall
Leader</td>
</tr>
<tr>
<td>Paris to Lyon</td><td>467km</td><td>Maurice Garin</td><td>Maurice
Garin</td>
/
The rowspan Attribute - 1
NCC Education Limited V1.0
</tr>
<tr>
<td>Lyon to Marseille</td><td>374km</td>
<td rowspan=" 2" >Hippolyte Aucouturier</td><td>Maurice Garin</td>
</tr>
<tr>
<td>Marseille to Toulouse</td><td>423km</td><td>Maurice Garin</td>
</tr>
</table>
Topic 6 HTML Tables Designing and Developing a Website
V1.0 Visuals Handout Page 5
HTML Tables Topic 6 - 6.13
The rowspan Attribute - 2
<td rowspan="2">Hippolyte Aucouturier</td>
NCC Education Limited V1.0
The rowspan attribute can be used to stretch a
table cell across multiple rows.
HTML Tables Topic 6 - 6.14
The <thead>, <tbody>and <tfoot>
Elements - 1
header
body
NCC Education Limited V1.0
We can specify rows as being part of the table
header, the table body or the table footer.
footer
y
HTML Tables Topic 6 - 6.15

<thead>
<tr>
<td>Stage</td><td>Distance</td><td>Stage Winner</td><td>Overall Leader</td>
</tr>
</thead>
The <thead>, <tbody>and <tfoot>
Elements - 2
We nest rows inside the <thead>,
<tbody>and <tfoot>elements
NCC Education Limited V1.0
<tfoot>
<tr>
<td>Total Distance</td><td>2,428 km</td>
</tr>
</tfoot>
<tbody>
<tr>

The <tfoot>element should be added


before the <tbody>.
<tbody>and <tfoot>elements.
Topic 6 HTML Tables Designing and Developing a Website
V1.0 Visuals Handout Page 6
HTML Tables Topic 6 - 6.16
Screenreaders linearise tables
Accessible Tables - 1
NCC Education Limited V1.0
Screen readers linearise tables.
Read out the contents in order
From left to right, top to bottom
In this example, the screen reader would read
Stage, Distance, Stage Winner, Overall Leader,
Paris to Lyon, 467km, Maurice Garin etc.
HTML Tables Topic 6 - 6.17
There are a number of HTML features which can
be used to enhance the accessibility of tables.
The <caption>element
The summary attribute
Accessible Tables - 2
NCC Education Limited V1.0
y
The <th>element
HTML Tables Topic 6 - 6.18
The <caption>Element
<table summary="This table is structured as four columns stage,
distance, the winner of the stage and the overall race leader at the end
of the stage">
<caption>Stage winners in the 1903 Tour de France</caption>
<thead>
<tr>
<td>Stage</td>
NCC Education Limited V1.0
The caption element provides a title for the table.
The summary element can be used to describe the
structure of the table.
Useful for complex tabular structures
<td>Stage</td>

Topic 6 HTML Tables Designing and Developing a Website


V1.0 Visuals Handout Page 7
HTML Tables Topic 6 - 6.19
The <th>element specifies that the cell contains
The <th>Element
<table>
<caption>Stage winners in the 1903 Tour de France</caption>
<tr>
<th>Stage</th><th>Distance</th><th>Stage Winner</th><th>Overall Leader</th>
</tr>
<tr>
<td>Paris to Lyon</td><td>467km</td>
NCC Education Limited V1.0
The <th>element specifies that the cell contains
table header information.
Describes the data
Distinguishes the headers from data
Screen readers use this header data
We should always use <th>elements when they are
appropriate.
HTML Tables Topic 6 - 6.20
The <colgroup>and <col>Elements
<table>
<caption>Stage winners in the 1903 Tour de France</caption>
<colgroup>
<col span=" 3" />
<col span=" 1" class=" overall_winner" />
</colgroup>
<tr>
<th>Route</th>

NCC Education Limited V1.0


The <col>and <colgroup>elements are used to label columns
The <col>element is used to identify a column.
The span attribute can be used to identify a series of
columns.
Useful for CSS
<colgroup>is used to group columns with related content.

HTML Tables Topic 6 - 6.21


Tables and CSS - 1
td, th {
padding: 5px;
border: 1px solid #000000;
}
NCC Education Limited V1.0
We can use CSS properties with tables.
By default, browsers add little styling to HTML
tables.
It is usual to specify borders and padding for table
cells.
Topic 6 HTML Tables Designing and Developing a Website
V1.0 Visuals Handout Page 8
HTML Tables Topic 6 - 6.22
Tables and CSS - 2
table {
border-collapse: collapse;
}
caption{
font-size:1.2em;
margin:10px;
NCC Education Limited V1.0
The border-collapse property is specific to tables.
Specifies if the cell borders are merged
The default value is separate.
We can also style the <caption>elements.
}
HTML Tables Topic 6 - 6.23
Highlighting Specific Cells
<tr>
<td>Bordeaux to Nantes</td><td>425km</td><td>Maurice Garin</td><td>Maurice
Garin</td>
</tr>
<tr id=" longest_stage" >
<td>Nantes to Paris</td><td>471km</td><td>Maurice Garin</td><td>Maurice
Garin</td>
</tr>
#longest_stage{
background-color:#ff00ff;
}
NCC Education Limited V1.0
We can style individual cells, rows and columns
using class and id attributes.
The <col>and <colgroup>elements allow us to
target columns.
</tr>

HTML Tables Topic 6 - 6.24


Before widespread browser support for CSS, tables
were often used for page layout.
With borders not visible, the table acts as a grid
setting out the page contents.
Using Tables for Page Layout - 1
NCC Education Limited V1.0
The following slide is a screen shot of the Amazon
website from August 2004.
Tables are used to design the page.
Amazon now have a CSS driven design.
Topic 6 HTML Tables Designing and Developing a Website
V1.0 Visuals Handout Page 9
HTML Tables Topic 6 - 6.25
Amazon - August 2004
NCC Education Limited V1.0
http://www.amazon.com/
HTML Tables Topic 6 - 6.26
NCC Education Limited V1.0
The red lines show the table borders.
Complex tables
Tables inside tables - nested tables
http://www.amazon.com/
HTML Tables Topic 6 - 6.27
Goes against web standards
CSS should be used for presentation
For page layout, we often need complex tables.
Time consuming to code
Using Tables for Page Layout - 2
NCC Education Limited V1.0
Time consuming to code
Difficult for screen readers to linearise
Difficult to maintain
With a CSS driven design, we only change the
external CSS file.
Topic 6 HTML Tables Designing and Developing a Website
V1.0 Visuals Handout Page 10
HTML Tables Topic 6 - 6.28
Tables do not work well on small screen sizes.
User has to scroll horizontally to view contents
Displaying complex tables can be computationally
intensive
Tables and Mobile Devices
NCC Education Limited V1.0
intensive.
Mobile devices have limited processing power
HTML Tables Topic 6 - 6.29
Chisholm, W. and May, M. (2008). Universal
Design for Web Applications: Web Applications
That Reach Everyone. O'Reilly Media.
References
NCC Education Limited V1.0
Duckett, J . (2010). Beginning HTML, XHTML, CSS,
and JavaScript. J ohn Wiley and Sons.
Kennedy, B. and Musciano,C. (2006). HTML &
XHTML: The Definitive Guide. O'Reilly Media.
HTML Tables Topic 6 - 6.30
Topic 6 HTML Tables
NCC Education Limited V1.0
Any Questions?

Das könnte Ihnen auch gefallen