website
Tables
1
Their place on the Web
Basic Table Markup
Tables and CSS
1
Tables
2
Introduced early in HTML history
Used initially to present certain types of data: numeric data, related data – pictures/description
Used as the fundamental structure for visual features of page –
presentation and content linked
2
Initially, there was no css, so tables were used to help layout the elements of a webpage.
Today css exists and has fully replaced tables for layout purposes.
The only purpose for tables is for true tabulated data.
Web Accessibility Review
HTML for CONTENT
CSS for PRESENTATION
JAVASCRIPT for BEHAVIOUR
3
3
Accessibility 101:
There should be no use of any presentation features in the html document.
These should be all transferred to the CSS file.
The table’s place on today’s Web
Tabulated data
As a way to lay out elements on a page
4
4
Tables should NEVER be used as a means of laying out elements on a webpage –
Eg multiple columns, image galleries, lists etc
All layout should be done by CSS
Parts of a Table
5
Table Data Cells
Table
Table Header Cells
Table
Row
5
Table tags
<table></table>
Contains the entire table
<th></th>
Signifies a table header row
<tr></tr>
Contains an entire row of a table
<td></td>
A general table data cell
6
6
Table cells
<th>
By default, data in a header is bold and centred
<td>
By default, table data will left align and render normal
7
7
Caption
It describes the content of the table
A visual element
Must follow the <table> start tag:
<table>
<caption>A Simple Table</caption>
<tr>
<td>One</td>
</tr>
</table>
Can only be one caption per table
Text appears outside the table and centred
8
8
The caption element is read by assistive software.
Getting Started
<table>
<caption>. . .</caption>
<tr>
<th>. . .</th>
<th>. . .</th>
</tr>
<tr>
<td>. . .</td>
<td>. . .</td>
</tr>
</table>
9
9
Where do they all fit together?
table – this is the wrapping element; everything to do with the table goes inside the start and end table tags
caption – this comes next after the start tag of the table element (note: does not go inside a tr element); this sits outside the table visually
tr – all data in a table must be held in rows, so the <tr> element starts and ends each table row
th – this is for headings; either column or row
td – a normal data cell
Create Some Tabular Information
Download vegetablePrices.txt
Copy and paste the text from vegetablePrices.txt into the html file
Markup the text as a table
Validate
10
10
Before you choose which table elements to put your text in, have a look at the text itself.
What would be the text that describes the table? – that’s what goes into the caption
Are there any row or column headings? – these go inside th elements
What looks like regular data? – put this inside td elements
More table tags
<thead></thead>
Allows a grouping of header rows
<tbody></tbody>
Allows a grouping of body rows
<tfoot></tfoot>
Allows a grouping of footer rows
11
<thead> <tr> <th>January</th> <th>February</th> </tr></thead>
<tbody> <tr> <td>Week 1</td> <td>$80</td> </tr></tbody>
<tfoot> <tr> <td>Sum</td> <td>$160</td> </tr></tfoot>
11
These elements give more meaning to a table.
Summary attribute
summaries the table’s purpose and structure
may be read by screen-reading software
Is obselete in HTML5
12
<table summary=“Names and times of some shows on Space – The Imagination Station.">
<caption>Space TV</caption>
<tr><td>Buffy the Vampire Slayer </td> <td>19:00</td> </tr>
<tr><td>Stargate SG-1</td>
<td>20:00</td> </tr>
<tr><td>Angel </td>
<td>23:00</td> </tr>
</table>
12
Much of what you will work with in web development will be existing, older site, you will still have to know how and why to use the summary attribute of the table element.
But be aware when developing anything in html5 that it is obselete in that iteration and will cause invalidation of your html5 pages.
Merging Table Cells: colspan
Allows a cell to span several columns
A <th> or <td> attribute
13
<table>
<tr>
<td colspan=“6”>Numbers</td>
</tr>
<tr>
<td>4 </td> <td>9</td>
<td>24</td> <td>33</td>
<td>37</td> <td>43</td>
</tr>
</table>
13
Merging table Cells: rowspan
Allows a cell to span several rows
A <th> or <td> attribute
14
<table >
<tr><td rowspan=“6”> Colours</td> <td>Blue</td>
</tr>
<tr><td>Red </td></tr>
<tr><td> Green </td></tr>
<tr><td> Yellow </td></tr>
<tr><td> Brown </td></tr>
<tr><td> Pink </td></tr>
</table>
14
Table border
Activates border around cells
Syntax:
<table border=“n” > where “n” is a value in pixels which controls the “thickness” of the border
15
Note: Will validate in XHTML Strict but better to use CSS border styles and colours instead
It’s often a good idea when first building a table to set the border to 1px thickness (border =“1”) in the html file, so that you can see if you’re building the table properly. Later style with CSS and remove the border attribute from the html file.
15
Table width
May be set in pixels or as a % of the screen size:
<table width=“95%” >
16
Note: Will validate in XHTML Strict but better to use CSS width instead
16
Cellpadding & Cellspacing
cellpadding
<table> attribute
Amount of space in pixels between the contents of the cells and the cell walls
Syntax
<table cellpadding=“5” >
cellspacing
<table> attribute
Amount of space between cells
Syntax
<table cellspacing=“2” >
17
Note: Will validate in XHTML Strict but better to use CSS padding and for spacing
17
Height & Width
May be set in pixels or as a percentage
<td width=“200” >One</td>
Certain rules apply to width
<table> values will override <td> values
Specify width at cell level when specification is necessary
Note: For XHTML Strict use CSS properties:
th, td { height: 100px; width: 200px; }
18
18
19
Accessible Tables
How does a screen reader read a table?
Most screen readers read the underlying code
Tabulated data can cause confusion or misunderstanding in interpretation if not used semantically
19
What’s all this talk about visual impairment?
How many people are blind or have visual impairment?
US statistics –
2008
approx 500,000 under age 18
Approx 25.2 million over age 18
Population 2009 – 300 million
Percentage who would benefit from assistive readers – approx 8.5%
20
20
When we are sighted and so are all our acquaintances it can be hard to realise big an issue accessibility is.
The above statistics come from the following site –
http://www.afb.org/Section.asp?SectionID=15
These statistics include people who are visually impaired enough to receive social benefits for their impairment.
Adult Definition and scope: The term vision loss refers to individuals who reported that they have trouble seeing, even when wearing glasses or contact lenses, as well as to individuals who reported that they are blind or unable to see at all. This estimate pertains to a nationally representative sample of the noninstitutionalized civilian population 18 years of age and over.
Australian statistics
2004
Total Australian population
20,328,609
Total Blind Australia (CERA Report 2004)
50,000
Total Vision Impaired (CERA Report 2004)
480,000
Equals – approx 1 in 40 people or 2.5%
21
21
http://www.bca.org.au/natpol/2005_Blind_Stats_num_and_perc_by_State_Territory_CERA.htm
Review - how does a Reader read?
Linear – across the page, line by line
Or by using the TAB key, jumping across or down
A good explanation can be read on the page listed below
22
Resource: http://www.webaim.org/techniques/screenreader/
22
Making a table accessible
Correct coding should result in the following:
Whole table can be read line by line, continuously or with sections selected manually.
Using keyboard commands, the user can move along rows and JAWS reads out the heading of the actual column plus the content of the cell.
Users can also read up and down columns in a similar way.
Users can select a cell and JAWS will present the information relating to the selected cell. That is, the cell content and, if the table has been coded correctly, the associated row and column headings.
23
23
Example with basic markup
| Lemons | Pears | |
| Wholesale | $1.00 | $1.50 |
| Retail | $2.00 | $2.50 |
24
<table border="1" summary="lemons and pears table with one level of row and column headers“ >
<caption> Prices for lemons and pears in Sydney </caption>
<tr>
<td></td>
<th>Lemons</th>
<th>Pears</th>
</tr>
<tr>
<th>Wholesale</th>
<td>$1.00</td>
<td>$1.50</td>
</tr>
<tr>
<th>Retail</th>
<td>$2.00</td>
<td>$2.50</td>
</tr>
</table>
Prices for lemons and pears in Sydney
24
Make sure you include table structure
<thead></thead>
Allows grouping of header rows
<tbody></tbody>
Allows grouping of body rows
<tfoot></tfoot>
Allows grouping of footer rows
25
25
26
<table border="1" summary="lemons and pears table with one level of row and column headers">
<caption>Prices for lemons and pears in Sydney</caption>
<thead>
<tr>
<td></td>
<th>Lemons</th>
<th>Pears</th>
</tr>
<thead>
<tbody>
<tr>
<th>Wholesale</th>
<td>$1.00</td>
<td>$1.50</td>
</tr>
<tr>
<th>Retail</th>
<td>$2.00</td>
<td>$2.50</td>
</tr>
<tbody>
</table>
| Lemons | Pears | |
| Wholesale | $1.00 | $1.50 |
| Retail | $2.00 | $2.50 |
Prices for lemons and pears in Sydney
26
Add id and headers attributes
The final addition to your markup is to add the id and headers attributes
This ensures the that data cells are linked with the appropriate headings.
Use this when you have extra levels of headings
And this makes table content easier to understand
27
27
id and headers attributes
28
the id attribute is used with the <th> element
AND used in conjunction with
the headers attribute within a <td> element
These attributes associate a cell with it’s heading
28
<tr>
<td></td>
<th id="beans">Beans</th>
<th id="peas">Peas</th>
<th id="carrots">Carrots</th>
<th id="tomatoes">Tomatoes</th>
</tr>
<tr>
<th id="darwin" colspan="5">Darwin</th>
</tr>
<tr>
<th headers="darwin" id="wholesale-darwin">Wholesale</th>
<td headers="beans darwin wholesale-darwin">$1.00</td>
<td headers="peas darwin wholesale-darwin">$1.25</td>
<td headers="carrots darwin wholesale-darwin">$1.20</td>
<td headers="tomatoes darwin wholesale-darwin">$1.00</td>
</tr>
29
Identify the different categories in your table
Link the column ids with the section you are in.
Try reading this out loud and see if it makes sense.
29
30
30
This is what it looks like.
Reference
31
31
Usability.com.au is an excellent, easy to read web site that offers solid, practical help for web developers in the Australian context.
Tables and CSS
32
32
CSS table properties
33
table-layout specifies the layout algorithm for a table element
Fixed – can be preset
Auto – cell content determines width
border-collapse specifies the border model for a table element
Separate – cell borders are spaced apart
Collapse – border collapsed into single border
Default is separate (detached)
border-spacing
sets the cell spacing between borders ONLY for a table element that uses the separated borders model
33
CSS table properties
34
empty-cells
only when using separated borders
Hides or shows empty cells
caption-side
specifies the position of the caption box relative to the table box
Top bottom left right
34
table
{
border-collapse: separate;
border-spacing: 1em 0.5em;
background-color: #ddd;
}
35
table
{
border-collapse: collapse;
}
35
36
row groups, column groups, rows, columns, and cells can have borders
Cells can also have padding
36
table {
border-collapse: collapse;
border: 1px solid black;
}
37
th{
text-align: left;
background: gray;
color: white;
padding: 0.2em;
}
td {
padding: 0.2em;
}
37