180 likes | 194 Views
Web Design (9). Tables. HTML Tables (1). HTML Tables may be used to organise calendars, schedules, statistics and other information that can be arranged in rows and columns. Cells within the html table may contain numbers, text, images or other multimedia objects. HTML Tables (2).
E N D
Web Design (9) Tables
HTML Tables (1) HTML Tables may be used to organise calendars, schedules, statistics and other information that can be arranged in rows and columns. Cells within the html table may contain numbers, text, images or other multimedia objects.
HTML Tables (2) Before style sheets (CSS), tables were the only option for creating multi-column layouts. When using html tables, problems arise with small screens and not being able to see the table as a whole e.g. bus timetables.
HTML Tables (3) All the table’s content goes into cells, arranged in rows. Cells contain header information or data. Tables use the following tags: <table> </table> <tr> </tr> table row <th> </th> table header cell <td> </td> table data cell
A Simple Table Example: A small table, with 3 rows and 3 columns, that lists nutritional information. Menu Item Calories Fat (g) Chicken Noodle Soup 120 2 Caesar Salad 400 26
Nutritional Data Exercise <table> <tr> <th>MenuItem</th> <th>Calories </th> <th>Fat(g) </th> </tr> <tr> <td>ChickenNoodle Soup</td> <td>120 </td> <td>2</td> </tr> <tr> <td>Caesarsalad</td> <td>400 </td> <td>26</td> </tr> </table>
Notes on HTML Tables • The <tr> element can only contain <td> and <th> elements. (2) The number of rows is defined by the number of <tr> elements, whereas the number of columns is defined by the number of <td> and <th> elements. (3) Within the <table> element, information can only be contained within a <td> or <th> element.
Bringing some shape to your table Returning to your ‘nutritonal information’ table, add the following attributes to the opening table tag: <tablewidth=“900”border=“1”align=“center”cellpadding=“4”cellspacing=“1”> Save, Validate, Live Preview. What do you notice? Now, change the attribute values and note how things change!
Exercise – Beatles Albums Create the code for an HTML Table using the following information: Album Year Rubber Soul 1965 Revolver 1966 Sgt. Pepper 1967 White Album 1968 Abbey Road 1969
Making cells larger (1) Column Spans The Column Span is created with the ‘colspan’ attribute in the <td> or <th> elements. It stretches a cell to the right to span over subsequent columns. Exercise: Write the following code into an html file in brackets:
Exercise – Colspan (1) <tablewidth=“ ” border=“” align=“” cellpadding=“ ” cellspacing=“”> <tr> <thcolspan=“2”>Fat</th> </tr> <tr> <td>Saturated Fat (g)</td> <td>UnsaturatedFat (g)</td> </tr> </table>
Exercise – Colspan (2) What do you notice about the table header <th> cell? The one item ‘Fat’ in the header is spread over 2 columns above the 2 items in the table data <td> cells.
TV Programmes Table (using colspan) Create the code for a HTML Table using the following TV Programme information: Start times: 7:00 7:30 8:00 BBC1 One ShowCountry File ITV1 Cricket HighlightsEmmerdale Film4 Lady and the Tramp (Notes: ‘One Show’ and ‘Emmerdale’ – half an hour; ‘Cricket Highlights’ and ‘Country File – one hour; ‘Lady and the Tramp’ – one hour and a half)
Making cells larger (2) Row Spans Row Spans are created with the ‘rowspan’ attribute. They cause the cell to span downward over several rows. Exercise: Write the following code into an html file in brackets:
Exercise: Rowspan (1) <table width=“” border=“” align=“” cellpadding=“ ” cellspacing=“”> <tr> <th rowspan=“3”>Serving Size </th> <td>Small(200g)</td> </tr> <tr> <td>Medium(400g)</td> </tr> <tr> <td>Large(600g)</td> </tr> <table>
Exercise: Rowspan (2) What do you notice about the table header <th> cell? The one item ‘Serving Size’ in the header is spread over 3 rows to the left of the 3 items in the table data <td> cells.
Fruit Exercise Create the code for an HTML table using the following information:
Describing table contents This is achieved by adding a <caption> ………..… </caption> element (with relevant text inside), just below the start <table> tag. Try this now with one of the exercises you have already completed and look at the Live Preview.