L04 HTML 2
L04 HTML 2
“To acquire knowledge, one must study; but to acquire wisdom, one must
observe.”
― Marilyn vos Savant
Contents
❖ HTML Elements
➢ Structure
➢ Paragraphs
➢ Headings
➢ Text
➢ Lists
➢ Hyperlinks
➢ Images
➢ Tables
Tags vs. Elements
• HTML specifies a set of tags that identify structure and content type
▪ tags are enclosed in < >
<img src="image.gif" /> specifies an image
</html>
Text Layout…
Headings: Separating Blocks of Text
<html>
<head> can specify headings for
<title>Blocks of Text</title>
</head> paragraphs or blocks of text
<body> ▪ <h1>…</h1> tags produce a large,
<h1>Major heading 1</h1>
<p> bold heading
Here is some text.
</p>
▪ <h2>…</h2> tags produce a slightly
smaller heading
<h2>Subheading</h2>
<p> ...
Here is some subtext. ▪ <h6>…</h6> tags produce a tiny
</p>
heading
<hr/>
</body>
</html>
Hyperlinks
perhaps the most important HTML
<html>
element is the hyperlink, or
<head>
<title>Hyperlinks</title>
ANCHOR
</head>
▪ <a href="URL">…</a>
<body> where URL is the Web address of the
<p> page to be displayed when the user
<a href="http://www.google.com">
Google University</a> clicks on the link
<br/> ▪ if the page is accessed over the Web,
<a href="page22.html" must start with http://
target="_blank">
Open page22 in a new window</a>
▪ if not there, the browser will assume it
</p> is the name of a local file
</body>
▪ <a href="URL" target="_blank">…</a>
</html>
▪ causes the page to be loaded in a new
Window
again, if file is to be accessed over the Web, must start with http:// (if not, will assume local file)
<html>
<head>
<title>Images</title>
</head>
<body>
<img src="w3javascript.png" alt=“JS” title=“JavaScript” />
<p>W3Schools JavaScript Tutorials</p>
</body>
</html>
Tables
• tables are common tools for arranging complex layout on a Web page
▪ a table divides contents into rows and columns
▪ by default, column entries are left-justified, so provide for alignment
<html>
<head>
<title>Tables</title> ● <table>…</table> specify a table
</head> element
<body>
<h2>A Simple Table</h2>
<table> ● <tr>…</tr> specify a row in the
<tr> table
<td> Left Column </td>
<td> Right Column </td>
● <td>…</td> specify table data (i.e.,
</tr>
<tr> each column entry in the table)
<td> Some data </td>
<td> Some data </td>
</tr>
</table>
</body>
</html>
Layout in a Table
<html> can have a border on tables using the
<head> “border” attribute
<title>Table Layout</title> <table style= “border: 1px solid;”>
</head>
increasing the number makes the border thicker
<body>
<table style="border: 1px solid;">
<tr style="text-align: center;"> can control the horizontal & vertical
<td style="border: 1px solid;">
layout within cells
Left<br/>Column</td> <td style= “text-align:center“>
<td style="border: 1px solid; <td style= “vertical-align: bottom">
vertical-align: top;">
Right Column</td>
</tr>
<tr> can apply layout to an entire row
<td style="border: 1px solid;"> <tr style=“text-align: center“>
Some data</td> <tr style=“vertical-align: top“>
<td style="border: 1px solid;">
Some data</td>
</tr>
</table> We will explore this more with
</body>
</html> Cascading Style Sheets.
Table Width
<html>
<head> by default, the table is sized to
<title>Table Width</title> fit the data
</head>
<body>
<table style="width: 100%;"> can override & specify the
<tr>
<td>left-most </td>
width of a table relative to the
<td style="text-align: page
right;">
right-most</td>
</tr> <table style=“width: 60%“>
</table>
</body>
</html>
Other Table Attributes
<html>
<head>
can control the space between cells &
<title>Table Formatting</title> margins within cells
<style type="text/css" media="screen">
This is the “padding” attribute in the table
table { border: 1px solid; padding: 1px;} and
th, td { border: 1px solid; padding: 10px; th,td style sheet declarations (more on this
text-align: center; }
</style> with Cascading Style Sheets).
</head> can add headings
<body> <th> is similar to <td> but displays
<table> heading centered in bold
<tr>
<th>HEAD1</th> <th>HEAD2</th> can have data that spans more than one
<th>HEAD3</th> column
</tr>
<tr>
<td colspan=“2”>
<td>one</td> <td>two</td> <td>three</td> similarly, can span more than one row
</tr>
<tr>
<td rowspan=“2”>
<td rowspan="2"> four </td> (This example uses CSS style sheet
<td colspan="2"> five </td>
</tr> commands in the page <header>.)
<tr>
<td> six </td> <td> seven </td>
</tr>
</table>
</body>
</html>
Frames
• frames provide the ability to split the screen into independent parts
Frames are going out of fashion, partly because they interact poorly with web
search engines (i.e. search engines cannot generally access the data stored in
the inset frame objects).
Frames can also “break” the regular behaviour of browsers, most notably the
“Back” button on the browser can behave in unexpected ways.
If you wish to design websites using frames, I would encourage you to use the
XHTML XFrames specifications (see the W3C website for more details), but
this specification isn’t fully supported by all browsers at this time.
Exercise
• Why do we need protocols?
• Write two applications of HTTP.
• READINGS
▪ M Schafer: Ch. 4, 5, 6, 7, 8
▪ https://www.w3schools.com/html
Acknowledgement
▪ http://www.csc.liv.ac.uk/~martin/teaching/comp519/