Lesson 4 Lists, Tables & Frames
Lesson 4 Lists, Tables & Frames
Lesson 4
Lecturer: Dr. Geoffrey Mariga, PhD
EMAIL: [email protected]
Contents
4.1 Lists
4.1.1 Ordered Lists
4.1.2 Unordered Lists
4.1.3 Definition Lists
4.1.4 Nested Lists
4.2 Tables
5.1 FRAMES
2
4.1 LISTs
Ordered Lists
Unordered Lists
Definition Lists
Nested Lists
3
4.1 LISTs
4.1.1 Ordered List - <ol>
Lists whose elements must appear in a certain order
Such lists usually have their items prefixed with a number or letter
An ordered list starts with the <ol> tag and finishes with </ol> tag.
<ol type=“a”>
<li>Apples</li> a. Apples
<li>Bananas</li> b. Bananas
<li>Coconuts</li> c. Coconuts
</ol>
5
4.1 LISTs
4.1.2 Unordered List - <ul>
Lists whose elements do not have to appear in a certain order.
An unordered list starts with the <ul> tag and finishes with
</ul> tag.
The list items are marked with bullets (typically small black
discs).
<ul>
<li>Apples</li> • Apples
<li>Bananas</li> • Bananas
<li>Coconuts</li> • Coconuts
</ul>
6
4.1 LISTs
4.1.2 Unordered List - <ul>
To change the type of a an unordered list, use
TYPE attribute in <OL> opening tag;
<ul type=”square”>
<li>Apples</li> Apples
<li>Bananas</li> Bananas
<li>Coconuts</li> Coconuts
</ul>
7
4.1 LISTs
4.1.3 Definition List - <dl>
8
4.1 LISTs
4.1.3 Definition List - <dl>
<dl>
<dt>Internet Explorer</dt>
<dd>Developed by Microsoft</dd>
<dt>Netscape</dt>
<dd>Developed by Netscape</dd>
</dl>
Internet Explorer
Developed by Microsoft
Netscape
Developed by Netscape
9
4.1 LISTs
4.1.4 Nested Lists
Contained in another list element
Lists can be nested of the same or different types
Nesting the new list inside the original;
Indents list one level and changes the bullet type to
reflect the Nesting
• Send us a letter, including:
<ul> 1. Your full name
<li>Send us a letter, including:</li> 2. Your order number
<ol> 3. You contact information
<li>Your full name</li> • Use the web form to send an email
<li>Your order number</li>
<li>Your contact information</li>
</ol>
<li> Use the web form to send an email </li>
</ul>
10
4.2 TABLEs
Tables are used when you need to show "tabular data" i.e. information that
is logically presented in rows and columns.
Building tables in HTML may at first seem complicated but if you keep cool
and watch your step, it is actually strictly logical - just like everything else in
HTML.
All tags and text that apply to the table go inside
<TABLE>…</TABLE> tags
TABLE Attributes;
BORDER: lets you set the width of the table’s border in pixels
ALIGN: specifies the horizontal alignment of the content in the entire
table, in a row or in a single cell. For example, left, center or right.
WIDTH: pixels (absolute) or a percentage
VALIGN: specifies the vertical alignment of the content in a cell. For
example, top, middle or bottom.
11
4.2 TABLEs
CAPTION element is inserted directly above the table in the
browser window
Helps text-based browsers interpret table data
TABLE Elements
THEAD element
Header info
TBODY element
Used for formatting and grouping purposes
12
4.2 TABLEs
A table is divided into rows
<TR>…</TR>
stands for "table row"
<TH>…</TH>
suitable for titles and column headings
13
4.2 TABLEs
<TD>...</TD>
stands for "table data".
starts and ends each cell in the rows of the table.
holds the content of a data cell.
used in the body part of a table.
aligned left by default.
a <td> tag can contain
text, links, images, lists, forms, other tables, etc.
14
4.2 TABLEs
Possible to make some data cells larger than others
Cells can be merged with the rowspan and colspan attributes
The values of these attributes specify the number of rows or
columns occupied by the cell
Can be placed inside any data cell or table header cell
Modified cells will cover the areas of other cells
Reduces number of cells in that row or column
15
4.2 TABLEs
<html>
<body>
Horizontal Headers:
<h4>Horizontal Headers:</h4>
<table border="1">
Name Telephone Telephone
<tr>
<th>Name</th> Bill Gates 555 77 854 555 77 855
<th>Telephone</th>
<th>Telephone</th>
</tr>
<tr>
<td>Bill Gates</td>
<td>555 77 854</td>
<td>555 77 855</td>
</tr>
</table>
</body>
</html> 16
4.2 TABLEs
<html>
<body>
<h4>Vertical Headers:</h4> Vertical Headers:
<table border="1">
<tr>
First Name: Bill Gates
<th>First Name:</th>
<td>Bill Gates</td> Telephone: 555 77 854
</tr> Telephone: 555 77 855
<tr>
<th>Telephone:</th>
<td>555 77 854</td>
</tr>
<tr>
<th>Telephone:</th>
<td>555 77 855</td>
</tr>
</table>
</body>
</html> 17
4.2 TABLEs
<table border="1">
<caption> TABLE 1 </caption>
<THEAD>
<tr>
<th>Header 1</th> TABLE 1
<th>Header 2</th> Header 1 Header 2
</tr>
</THEAD> row 1, cell 1 row 1, cell 2
<TBODY> row 2, cell 1 row 2, cell 2
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</TBODY>
</table>
18
4.2 TABLEs
<html>
<body>
<h4>Cell that spans two columns:</h4>
<table border="1">
<tr><th>Name</th>
<th colspan="2">Telephone</th></tr>
<tr> Cell that spans two columns:
<td>Bill Gates</td>
<td>555 77 854</td> Name Telephone
<td>555 77 855</td>
Bill Gates 555 77 854 555 77 855
</tr>
</table> Cell that spans two rows:
<h4>Cell that spans two rows:</h4> First Name: Bill Gates
<table border="1">
<tr><th>First Name:</th><td>Bill Gates</td></tr> 555 77 854
<tr><th rowspan="2">Telephone:</th> Telephone:
<td>555 77 854</td>
555 77 855
</tr>
<tr><td>555 77 855</td></tr>
</table>
</body>
</html>
19
4.2 TABLEs
COLGROUP element
Used to group and format columns
20
4.2 TABLEs
21
4.2 TABLEs
22
4.2 TABLEs
23
4.2 TABLEs
24
5.1 FRAMEs (not suppurted in HTML5!!!)
Frames allow you to have multiple sections of the browser
window, called frames, each showing their own .html file
within the frame.
This used to be common practice when trying to show
separate sections of a site in separate sections of the
browser window, such as a header at the top, navigation
at the side, and the rest was page content that someone
could scroll down without making the header and
navigation disappear.
Frames in HTML documents are created and controlled
through the structure of three element types:
FRAMESET,
FRAME,
NOFRAMES.
25
5.1 FRAMEs (not suppurted in HTML5!!!)
The structure of a frame-enabling HTML document type is
similar to usual HTML structure. The key difference in an
HTML document type is that the BODY container element
is basically replaced by a FRAMESET container element.
The initial FRAMESET element describes the frames that
make up the page, and the FRAME elements specify the
sub-documents that appear initially in each.
If used properly, frames make your site more readable
and usable
The disadvantages of using frames are:
Frames are not supported in HTML5!!!
Frames are difficult to use. (Printing the entire page is
difficult).
The web developer must keep track of more HTML
documents 26
5.1 FRAMEs (not suppurted in HTML5!!!)
The HTML frameset Element
<FRAMESET>
Tell the browser that the page contains frames
Holds one or more frame elements.
COLS or ROWS attributes states;
How many columns or rows there will be in the
frameset, and
How much percentage/pixels of space will occupy
each of them.
In the frameset, one of the columns or one of the rows
can be set to use the remaining space, with an asterisk
( * ).
27
5.1 FRAMEs (not suppurted in HTML5!!!)
The HTML frameset Element
<FRAMESET> - Examples
<frameset cols="30%,70%">
<frameset rows="30%,70%">
<frameset cols="200,500">
<frameset cols="25%,*">
<frameset cols="25%,*,25%">
<frameset rows="25%,*,25%">
<frameset rows="30%, 20%,* ">
28
5.1 FRAMEs (not suppurted in HTML5!!!)
The HTML frame Element
The <frame> tag defines one particular window (frame)
within a frameset and has no end tag.
Each frame element can hold a separate document.
In the example below we have a frameset with two
columns.
the first column is set to 25% of the width of the
browser window.
the second column is set to 75% of the width of the
browser window.
the document "frame_a.html" is put into the first
column, and the document "frame_b.html" is put into
the second column:
<frameset cols="25%,75%">
<frame src="frame_a.html" />
<frame src="frame_b.html" />
</frameset>
29
5.1 FRAMEs (not suppurted in HTML5!!!)
The HTML frame Element
FRAME attributes:
32
5.1 FRAMEs (not suppurted in HTML5!!!)
How to use <noframes> tag
<head>
<title>...</title>
</head>
<frameset cols="25%,50%,25%">
<frame src="frame_a.html">
<frame src="frame_b.html">
<frame src="frame_c.html">
</frameset>
</html>
33
5.1 FRAMEs (not suppurted in HTML5!!!)
How to use <noframes> tag
RESULT:
34
5.1 FRAMEs (not suppurted in HTML5!!!)
Nested <FRAMESET> Tags
<frameset cols="20%,80%">
<frame src="frame_a.html">
<frameset rows="80%,20%">
<frame src="frame_b.html">
<frame src="frame_c.html">
</frameset>
</frameset>
</html>
35
5.1 FRAMEs (not suppurted in HTML5!!!)
Nested <FRAMESET> Tags
RESULT:
36
5.1 FRAMEs (not suppurted in HTML5!!!)
Example for Nested Frames:
<HTML>
<HEAD></HEAD>
<NOFRAMES>
<P>This page uses frames, but your browser doesn't support them.</P>
<P>Get Internet Explorer at the
<A HREF = "http://www.microsoft.com/">MicrosoftWebSite</A></P>
</NOFRAMES>
</FRAMESET>
</HTML>
37
5.1 FRAMEs (not suppurted in HTML5!!!)
Result:
38
5.2 IFRAMEs
iFrame is used to display a web page within a web page.
Set Height and Width
The height and width attributes are used to specify the
height and width of the iframe.
The attribute values are specified in pixels by default, but
they can also be in percent (like "80%").
39
5.2 IFRAMEs
Use iframe as a Target for a Link
An iframe can be used as the target frame for a link.
The target attribute of a link must refer to the name
attribute of the iframe:
40