Professional Documents
Culture Documents
B2 WebTech1 HTML-1
B2 WebTech1 HTML-1
Dr Jingpeng Li
http://www.cs.stir.ac.uk/~jli/
Room 4B95
What to Expect…
1
Three Aspects of Web Development
• Content (HTML)
• Presentation (CSS)
• Interactivity (JavaScript)
Resources
2
Spring 2019 © University CSCU9B2: Making the Most of the 5
of Stirling World Wide Web
3
HTML5 + Character Encoding
<!DOCTYPE html>
<html> • Meta tags provide
<head> housekeeping information
<meta charset="utf-8"> • One is the character
<title>My First Web Page</title> encoding used
</head>
<body> • utf-8 is Unicode
<p> • guarantees correct
Hello world. rendering by the browser
</p>
<p>
It is a <em>wonderful</em> day,
today!
</p>
</body>
</html>
Spring 2019 © University CSCU9B2: Making the Most of the 7
of Stirling World Wide Web
XHTML Version
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>My First Web Page</title>
</head>
<body>
<p>
Hello world.
</p>
<p>
It is a <em>wonderful</em> day, today!
</p>
</body>
</html>
Spring 2019 © University CSCU9B2: Making the Most of the 8
of Stirling World Wide Web
4
HTML Validation: http://validator.w3.org/
5
Web Pages the WYSIWYG Way
• There are WYSIWYG editors for HTML
– What You See Is What You Get
– we do not type in actual HTML
– the HTML is created for us behind the scenes
– e.g.
• Adobe Dreamweaver
• Microsoft FrontPage
• All such editors have limitations
– Know your HTML first!
• Example ...
Spring 2019 © University CSCU9B2: Making the Most of the 11
of Stirling World Wide Web
<p>
Hello world.
Body </p>
<p>
It is a <em>wonderful</em> day, today!
</p>
</body>
</html>
6
Formatting Text
HTML Tags
7
HTML Tags (2)
• Most tags are containers:
<em>wonderful</em>
• There are also standalone tags, e.g.
<img> - inline image
<br> - linebreak In XHTML:
<br />
<hr> - horizontal rule
• Most elements have attributes
– these extend or modify the tag’s actions
– e.g. <p class="important"> … </p>
8
Things to Note
• Some things are ignored by browsers:
– Line breaks are ignored
• text is wrapped continuously until <p> or <br>
– Tabs and white space are ignored
– Multiple <p> tags are ignored (one will do)
– Unrecognised tags are ignored
• (this can have unfortunate effects!)
9
Comments in HTML
10
Header Tags
• <title>…</title>
– description of page’s contents
– usually displayed in browser’s header bar
– used in bookmarks and by search engines
• <base>
– specifies the base URL/target for all relative URLs in a
document
• <meta>
– provide information about document, e.g. author
– used by search engines
Example Header
<!DOCTYPE html>
<html>
<head>
<base href= "http://www.cs.stir.ac.uk/courses/CSCU9B2">
<meta http-equiv="content-type" content=“text/html; charset=UTF-8">
<meta name="Author" content=“J.Li">
<title>My First Web Page</title>
</head>
<body>
:
:
</body>
</html>
11
Inside the Body: Headings
• Heading levels
– <h1> to <h6>
– <hn>…</hn>
– e.g. <h1>Heading One</h1>
Paragraphs
• Paragraphs delimited by <p>…</p>
• Browser determines lines
– use <br> to force a break
12
Preformatted Paragraphs
• Use <pre>…</pre> to create a paragraph with
line breaks and spacing as you specified
– usually displayed in a monospace font, e.g. Courier
Text Styles
• Logical styles
– specific rendering left to browser
<strong>…</strong> emphasis (usually bold)
<em>…</em> emphasis (usually italic)
<mark>…</mark> highlight (HTML5 only)
<code>…</code> computer code (monospaced)
• Physical styles
– specific display instructions
<i>…</i> italic
<b>…</b> bold
<sub>…</sub> subscript
<sup>…</sup> superscript
Spring 2019 © University CSCU9B2: Making the Most of the 26
of Stirling World Wide Web
13
Special Characters
• Characters not found in the normal
alphanumeric character set are specified
using character entities
• These may be defined by name: &name;
– e.g. È - grave accent on capital E (È)
– these are case-sensitive! (e.g. è for è)
• Or by a number: &#nnn;
– e.g. > - greater than sign (>)
• (In both cases, note the semicolon)
Spring 2019 © University CSCU9B2: Making the Most of the 27
of Stirling World Wide Web
Including Images
• Images can be included in-line anywhere in
your document using <img>
– e.g. <img src="mypicture.gif" alt="Picture of me"
width="50" height="50">
– src (required) specifies the location of the image
• relative or full URL (see later)
– alt (required) specifies alternative textual
description
– width and height of image in pixels
• Image formats are GIF, JPEG and PNG
14
Spring 2019 © University CSCU9B2: Making the Most of the 29
of Stirling World Wide Web
Other Media
• <object> is a way of including a variety of
media elements in a web page
– Audio, video, Java applets, PDF, Flash
– e.g. <object width="400" height="400"
data="helloworld.swf">Hello world!</object>
– data specifies the location of media
– Alternative text is content of tag
• Alternatively in HTML5 use:
– <audio> for sound clips
– <video> for video clips
15
Hypertext Links
16
Links with Absolute URLs
• Remote pages are linked with absolute URLs
– the complete URL, e.g.
Here’s a link to Jingpeng’s
<a href=“http://www.cs.stir.ac.uk/~jli/Publications.html”>
research page</a>.
• A URL with no HTML file finds a default page
– defined by server
– either index.html or default.html (default.htm)
Here’s a link to Jingpeng’s
<a href=“http://www.cs.stir.ac.uk/~jli/”> home page</a>.
Spring 2019 © University CSCU9B2: Making the Most of the 33
of Stirling World Wide Web
17
Linking Within a Document
• Parts of a document can be named (given an
identifier):
– e.g. <h1 id=“stocks”>Daily Stock Quotes</h1>
• Elsewhere in the same document we may
place a link:
– e.g. Check out the <a href=“#stocks”>stock
quotes</a>
• And in another document we may include
Go to today’s
<a href=“dailynews.html#stocks”>stock quotes</a>
Table of Contents
• Links to
parts of a
document
are very
useful for
tables of
contents
within a long
document
18
Links to Other Media
• Links to images:
e.g. Here is <a href=“alan.jpg”>me</a>.
• Links to email addresses:
e.g. <a href=“mailto:jli@cs.stir.ac.uk”>Mail me</a>
• Links to other types of document:
e.g. <a href=“mydoc.pdf”>my document</a>
– requires non-browser software to view it, either
stand-alone or browser plugin
Thumbnail Images
• Images are usually big and can take a long time
to download
• Often use a thumbnail-sized image as a link to
the full image, using <a>
– the target attribute tells the browser to open a new
window:
<a href=“bruce.jpg” target=“myimage”>
– it helps to indicate size of full image near thumbnail
– user has choice as to whether to download or not
• More details ...
Spring 2019 © University CSCU9B2: Making the Most of the 38
of Stirling World Wide Web
19
<p>
<a href="bruce.jpg" target="myimage">
<img src="bruce65x75.jpg" alt=“me"></a>
Click the thumbnail
to see a larger image of me!
</p>
Lists in HTML
20
Unordered (Bulleted) Lists
• <ul>…</ul>
• List entries with <li>…</li>
• Bullet style can be set with style sheets
<p><b>Shopping List</b></p>
<ul>
<li>Avocados</li>
<li>Tomatoes</li>
<li>Scallions</li>
<li>Black beans</li>
</ul>
21
Definition Lists
• <dl>…</dl>
• Term with <dt>…</dt>
• Definition with <dd>…</dd>
<p><b>Some Definitions</b></p>
<dl>
<dt>Internet</dt>
<dd>Network of networks.</dd>
<dt>World Wide Web</dt>
<dd>Distributed system of hypertext
documents known as web pages.</dd>
<dt>HTML</dt>
<dd>Hypertext markup language.</dd>
</dl>
Spring 2019 © University CSCU9B2: Making the Most of the 43
of Stirling World Wide Web
Nested Lists
• Lists can be nested
– Browser automatically changes bullet style for
unordered lists
– Ordered lists can also be nested but change
numbering style with style sheets
<ul>
<li>Breakfast
<ul>
<li>Cereal</li>
<li>Toast</li>
<li>Coffee</li>
</ul></li>
<li>Lunch</li>
<li>Dinner</li>
</ul>
Spring 2019 © University CSCU9B2: Making the Most of the 44
of Stirling World Wide Web
22
Style in Lists with CSS
<head>
<meta charset="utf-8">
<style type="text/css">
ul.cir { list-style-type: circle; }
ul.squ { list-style-type: square; }
ol.upA { list-style-type: upper-alpha; }
ol.lor { list-style-type: lower-roman; }
</style>
<title>Examples of Lists</title>
</head>
<body>
<h3>Shopping List</h3>
<ul class="squ">
<li>Avocados</li>
<li>Tomatoes</li>
<li>Scallions</li>
<li>Black beans</li>
</ul>
Tables
• Rows and columns of tabular data
23
A Very Simple Table
• As basic as it gets…
<table>
<tr>
<td>Cell 1</td><td>Cell 2</td>
</tr>
<tr>
<td>Cell 1</td><td>Cell 2</td>
</tr>
</table>
24
Spanning Columns
<table border=“1”>
<caption>A Complicated Table</caption>
<tr>
<td rowspan=“3”>Cell 1</td>
<td colspan=“2”>Cell 2</td>
</tr>
<tr>
<td>Cell 3</td><td>Cell 4</td>
</tr>
<tr>
<td>Cell 5</td><td>Cell 6</td>
</tr>
</table>
Note: caption
Table Sizing
• Table and cell widths can be specified
using style sheets
• Relative sizing
– Table relative to size of browser window
– Cell relative to table size
• Absolute sizing in pixels
<table border=“1”>
<tr>
<td class=“narrow”>Left-hand</td>
<td>Right-hand</td>
</tr>
</table>
Spring 2019 © University CSCU9B2: Making the Most of the 50
of Stirling World Wide Web
25
Sizing (contd)
<HTML>
<HEAD>
<TITLE>A Two Column Table Layout</TITLE>
<STYLE type="text/css">
<TABLE BORDER=1>
.whole {width: 100%}
<TR>
.narrow {width: 20%}
<TD CLASS="narrow">Left-hand column for
.narfix {width: 40px}
links</TD>
</STYLE>
<TD>Right-hand column for content</TD>
</HEAD>
</TR>
</TABLE>
<TABLE BORDER=1>
<TR>
<TABLE BORDER=1>
<TD>Left-hand column for links</TD>
<TR>
<TD>Right-hand column for content</TD>
<TD CLASS="narfix">Left-hand column for
</TR>
links</TD>
</TABLE>
<TD>Right-hand column for content</TD>
</TR>
<TABLE BORDER=1 class="whole">
</TABLE>
<TR>
<TD CLASS="narrow">Left-hand column for
</BODY>
links</TD>
</HTML>
<TD>Right-hand column for content</TD>
</TR>Spring 2016 © University CSCU9B2: Making the Most of the 51
of Stirling
</TABLE> World Wide Web
26
End of Lecture
27