Académique Documents
Professionnel Documents
Culture Documents
WEEK
COMP1223
Web Development Fundamentals
L E C T U R E
N O T E
2015
External Sources:
http://www.w3.org/wiki/HTML_tables
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table
http://www.w3schools.com/css/css_pseudo_classes.asp
https://css-tricks.com/how-nth-child-works/
PAGE: 1
Table of Contents
Contents
Objectives ..................................................................................................................................................... 3
An Introduction to tables .............................................................................................................................. 4
Summary ................................................................................................................................................... 4
How to create a table.................................................................................................................................... 5
Common elements for coding tables ........................................................................................................ 5
Summary ............................................................................................................................................... 5
How to use CSS to format a table ................................................................................................................. 5
Sample CSS ................................................................................................................................................ 6
How to add a header and footer .................................................................................................................. 7
Example ..................................................................................................................................................... 7
HTML ..................................................................................................................................................... 7
CSS ......................................................................................................................................................... 8
How to merge cells in a column or row ........................................................................................................ 8
Example ..................................................................................................................................................... 8
PAGE: 2
Objectives
Applied
1. Use HTML to create tables with merged cells, captions, headers, and footers.
2. Use CSS and the CSS3 structural pseudo-classes to format the tables that you create.
3. Use the HTML5 figure and figcaption elements to treat a table as a figure.
4. Use HTML to provide accessibility for tables.
Knowledge
1. Describe these components of a table: rows, columns, cells, header cells, data cells, table header, table
footer, and table body.
2. Describe the proper use of tables, now that CSS should be used for page layout.
3. Describe the use of nesting and wrapping with tables.
4. Describe the use of the table attributes for accessibility.
PAGE: 3
An Introduction to tables
The HTML Table Element (<table>) represents data in two dimensions or more. A table consists of one
or more rows and columns.
-
There are two different kinds of cells. Table header (<th>) and data cell (<td>)
A table can start with a header section then body section and last footer section which provides
summary.
Note: Prior to the creation of CSS, HTML <table> elements were often used as a method for page layout.
This usage has been discouraged since HTML 4, and the <table> element should not be used for layout
purposes. However, HTML emails are an exception, where tables are still commonly used for layout
purposes.
Summary
PAGE: 4
Summary
Note: Number of columns must be the same for all the tables rows in the same table.
PAGE: 5
Sample CSS
PAGE: 6
Example
HTML
PAGE: 7
CSS
Note: The thead, tbody, tfoot elements make it easier to style a table with CSS
To merge cells so a cell in a row spans two or more coluns, you use the colspan attibute.
To merge cells so a cell in a columnspans two or more rows, you use the rowspan attibute.
Example
PAGE: 8
PAGE: 9
PAGE: 10
Summary
PAGE: 11
PAGE: 12
Specify a background color for every <p> element that is the second child of its parent, counting from
the last child
PAGE: 13