Lec 2-HTML - 1.5m
Lec 2-HTML - 1.5m
Objectives
2
Outline
1. Basic HTML
• hypertext
• tags & elements
• text formatting
• lists, hyperlinks, images
• tables
2. HTML5
3
Hypertext & HTML
4
Hypertext & HTML (cont.)
5
Tags and Elements
6
Structural Elements
<html>
<!–- First file---->
<head>
HTML documents : <html> and </html> tags
<title>My first HTML document</title> Comments: <!-- and -->
</head>
<body> HEAD section: <head> and </head> tags
<p> Hello world! </p>
</body> BODY section: <body> and </body>
</html>
view page
7
<head> and <body> elements
•<head> element
• Title
• Metadata, such as who authored the page, keywords
• Cascading Style sheet information
• JavaScript code
•The <body> element
• Paragraphs
• Tables and lists
• Images
• JavaScript code
• PHP code
8
Text Layout
<html>
<!–- CS443 page02.html 17.09.14 -->
<head>
<title>Text Layout</title>
</head>
• For the most part, layout of the text is
<body>
<p>
left to the browser
This is a paragraph of text<br/>
made up of two lines.
• whitespace is interpreted as a single space
</p> • browser automatically wraps the text to fit
<p> the window size
This is another paragraph with a
GAP between
some of the words.
• Can override some text layout
</p>
• can specify a new paragraph (starts on a
<p> new line, preceded by a blank line) using
This paragraph
is<br/> <p>…</p>
indented on the first line<br/>
but not on subsequent lines. • can cause a line break using the <br/>
</p>
</body> • can force a space character using
</html>
view page
9
Separating Blocks of Text
<html>
<!–- CS443 page03.html 15/08/06 -->
<head>
<title>Blocks of Text</title>
</head> • Can specify headings for
<body> paragraphs or blocks of text
<h1>Major heading 1</h1>
<p>
Here is some text.
•<h1>…</h1> tags produce a large,
</p> bold heading
<h2>Subheading</h2> •<h2>…</h2> tags produce a
<p>
Here is some subtext.
slightly smaller heading
</p> •. . .
<hr/> •<h6>…</h6> tags produce a tiny
<h1>Major heading 2</h1> heading
<p>
Here is some more text.
</p>
</body>
• Can insert a horizontal rule
</html>
•<hr/> draws line across window
view page
10
The Basic Web page – A Worked Example
<html>
<!–- CS443 page22.html 17.10.14 -->
<head>
<title> Bill Smiggins Inc. </title>
</head>
<body>
<h1>Bill Smiggins Inc.</h1>
<h2>About our Company...</h2>
<p>This Web site provides clients, customers,
interested parties and our staff with all of
the information that they could want on
our products, services, success and failures.
</p>
<hr/>
<h3> Products </h3>
<p> We are probably the largest
supplier of custom widgets, thingummybobs, and bits
and pieces in North America. </p>
<hr/>
</body>
</html>
view page
11
Text Appearance
<html>
<!–- CS443 page25.html 15.08.06 -->
<head>
<title>Text Variations and Escape
• can specify styles for fonts
Sequences</title>
</head> •<b>… </b> specify bold
<body>
<h1>Text Variations</h1>
<p>We can use <b>simple</b> tags to •<i>… </i> specify italics
<i>change</i> the appearance of
<strong>text</strong> within •<big>… </big> increase the size
<tt>Web pages</tt>.
Even super<sup>script</sup>
and sub<sub>scripts</sub> are
•<small>… </small> decrease the size
<em>supported</em>.</p>
•<em>…</em> put emphasis
<h1>Text Escape Sequences</h1>
<p>
& < > " ©
•<strong>…</strong> put more emphasis
</p>
<h1>Preformatted text</h1> •<sub>… </sub> specify a subscript
<pre>
University of Liverpool
Department of Computer Science
•<sup>… </sup> a superscript
Ashton Building, Ashton Street
Liverpool, L69 3BX, UK
</pre>
</body>
</html>
view page
12
Lists
<html>
<!–- CS443page07.html 23.09.08 -->
<head> <title>(Sort of) Simple
Lists</title> • There are 3 different types of list
elements
<style type="text/css">
.my_li:before { content: counter(list)
": ";
counter-increment: list; • <ol>…</ol> specifies an ordered
list
}
</style> </head>
<body>
<ul style="list-style-type: square;"> • <li> identifies each list item
<li> ... first list item... </li>
<li> ... second list item... ... </li>
</ul>
<dl> <dt> Dweeb </dt> • <ul>…</ul> specifies unordered
<dd> young excitable person who may
mature into a <em>Nerd</em> </dd> list (using a bullet for each)
<dt> Hacker </dt>
<dd> a clever programmer </dd> • <li> identifies each list item
<dt> Nerd </dt> <dd> technically bright
but
socially inept person </dd>
</dl>
<ol style="list-style-type: none;
• <dl>…</dl> specifies a definition
counter-reset: list 29;" > list
<li class="my_li">Makes first item number
30.</li>
<li class="my_li">Next item continues to
• <dt> identifies each term
number 31.</li>
</ol>
• <dd> identifies its definition
</body> view page
</html>
13
Hyperlinks
<html>
<!–- CS443page08.html 17.10.14 -- • Perhaps the most important HTML
>
element is the hyperlink, or ANCHOR
<head>
<title>Hyperlinks</title>
</head>
• <a href="URL">…</a>
<body>
•URL is the Web address
<p>
<a href="http://www.liv.ac.uk"> •<a href="URL"
The University of Liverpool</a>
<br/> target="_blank">…</a>
• causes the page to be loaded in a
<a href="page07.html"
target="_blank">
Open page07 in a new window</a>
</p> new Window
</body>
</html>
view page
14
Hyperlinks (cont.)
<html>
<!–- CS443 page09.html 21.09.12 -->
• for long documents, you can even
<head> have links to other locations in that
<title>Internal Links in a Page</title>
</head> same document
<body> • <xxxx id="ident">…</xxxx>
<p>
[ <a href="#HTML">HTML</a> |
<a href="#HTTP">HTTP</a> |
• ident is a variable for identifying
<a href="#IP">IP</a> |
<a href="#TCP">TCP</a> ]
this location
</p>
<p>
• "xxxx" can be any HTML element
Computer acronyms:
<dl>
<dt id="HTML">HTML</dt>
<dd>HyperText Markup Language • <a href="#ident">…</a>
<dt id="HTTP">HTTP</dt>
<dd>HyperText Transfer Protocol…</dd>
<dt id="IP">IP</dt>
• will then jump to that location
<dd>Internet Protocol…</dd>
<dt id="TCP">TCP</dt>
within the file
<dd>Transfer Control Protocol…</dd>
</dl>
</p>
• <a href="URL#ident">…</a>
• can jump into the middle of
</body>
</html>
another file
view page
15
Images
<html>
<!–- CS443 page10.html 18.09.13 -->
<head>
<title>Image example</title>
</head>
<body>
<img
src="http://www.csc.liv.ac.uk/~martin/teaching/comp519/HTML/Cathedral.jpg"
title="Liverpool's Anglican cathedral"
alt="image of Liverpool's Anglican Cathedral" width="400" />
view page
16
Images (cont.)
17
Tables
<html>
<!–- CS443 page11.html 17.10.14 --
>
<head>
<title>Tables</title> <table>…</table> specify a table
</head>
<body> element
<h2>A Simple Table</h2>
<table>
<tr>
<td> Left Column </td> <tr>…</tr> specify a row in the table
<td> Right Column </td>
</tr>
<tr>
<td> Some data </td>
<td>…</td> specify table data (i.e., each
<td> Some other data </td>
</tr>
column entry in the table)
</table>
</body>
</html>
view page
18
Layout in a Table
<html>
<!-- CS443 page12.html 17.10.14 --> • Border on tables using the “style” attribute
<head> <table style= "border: 1px
<title>Table Layout</title>
</head> solid;">
<body>
<table style="border: 1px solid;">
<tr style="text-align: center;">
• Horizontal & vertical layout within cells
<td style="border: 1px solid;">
Left<br/>Column</td>
<td style= "text-align:center">
<td style="border: 1px solid; <td style= "vertical-align:
vertical-align: top;">
Right Column</td> bottom">
</tr>
<tr>
<td style="border: 1px solid;">
Some data</td> • Layout to an entire row
<td style="border: 1px solid;">
Some data</td> <tr style="text-align: center">
</tr>
</table> <tr style="vertical-align:
</body>
</html> top">
view page
19
Table Width
<html>
<!-- CS443 page13.html 17.10.14 -->
<head>
• by default, the table is sized to fit
<title>Table Width</title> the data
</head>
<body>
• can override & specify the width of
<table style="width: 100%;"> a table relative to the page
<tr>
<td>left-most </td>
<td style="text-align: right;">
For example
right-most</td> <table style="width: 60%">
</tr>
</table>
</body>
</html>
view page
20
Other Table Attributes
<html>
<!-- CS443 page14.html 17.10.14 -->
<head>
•Can control the space between cells &
<title>Table Formatting</title>
margins within cells using “padding” attribute
<style type="text/css" media="screen">
table { border: 1px solid; padding: 1px;}
th, td { border: 1px solid; padding:
10px;
text-align: center; } • Can add headings
<th> is similar to <td> but displays
</style>
</head>
<body>
<table>
heading centered in bold
<tr>
<th>HEAD1</th> <th>HEAD2</th>
<th>HEAD3</th>
</tr>
<tr>
• Can have data that spans more than one
<td>one</td> <td>two</td> <td>three</td>
</tr> column
<tr>
<td rowspan="2"> four </td> <td colspan="2">
<td colspan="2"> five </td>
</tr>
<tr>
view page
21
Outline
1. Basic HTML
2. HTML5
22
TRƯ Ờ NG CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG
School of Inform ation and Com m unication Technology
23
HTML5 New Tags
24
HTML5 New Tags
Footer
25
HTML5 New Tags
<audio controls="true">
<source src="audiodemo.ogg"
/>
<source src=" audiodemo.mp3"
/>
<source src=" audiodemo.wav"
/>
Not supported.
</audio>
26
HTML5 New Tags
• <canvas> element:
function draw() {
var ctx =
document.getElementById('canvas').getContext('2d');
var img = new Image();
img.onload = function(){
ctx.drawImage(img,0,0);
ctx.beginPath();
ctx.moveTo(30,96);
ctx.lineTo(70,66);
ctx.lineTo(103,76);
ctx.lineTo(170,15);
ctx.stroke();
}
img.src = 'images/backdrop.png';
}
27
HTML5 New Tags
month
button number
checkbox password
color radio
date range
datetime reset
datetime-local search
email submit
file tel
hidden text
image time
url
week
28
Exercises
• https://www.w3schools.com/html/
• https://www.w3schools.com/html/exercise.asp
29