6 MoreHTML
6 MoreHTML
Chapter 4
Nesting Tags
How do you write the following in HTML?
2
Spacing And Indentation
Which tag is not closed?
<html><head><title>Can you find it?</title></head>
<body><p><ul><li>Not it!</li><li><ol><li>Is it here?
</li><li>Or maybe it's this one?</li></ol></li><li>
More words here</li><li>This is very hard to
read</li></p></body></html>
3
How About Now?
<html>
<head>
<title>Can you find it?</title>
</head>
<body>
<p>
<ul>
<li>Not it!</li>
<li>
<ol>
<li>Is it here?</li>
<li>Or maybe it's this one?</li>
</ol>
</li>
<li>More words here</li>
<li>This is very hard to read</li>
</p>
</body>
</html>
4
Spacing And Indentation Guidelines
If the tag's content fits on one line, open and close
the tag on the same line.
<li>Is it here</li>
6
Extensible HTML: XHTML
Newer version of HTML, standardized in 2000
7
Why Use Standards?
Ensure interoperability across different browsers
8
Basic XHTML Template
<?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">
<head>
<title>page title goes here</title>
</head>
<body>
page content goes here
</body>
</html>
9
HTML Element
10
Block vs. Inline Elements
Block elements create "larger" structures than inline
elements.
In general,
block elements may contain text, inline elements, and other
block elements.
inline elements may contain only text and other inline
elements.
11
Block or Inline?
Block Inline
h1, h2, ..., h6 br
p em
ul, ol strong
hr a
img
12
Document Flow: Block Elements
13
Document Flow: Inline Elements
14
Document Flow Example
15
Why Important?
Only block
elements are
directly allowed
inside the body
element.
Elements allowed
in body element
Illegal:
<body>
<a href="http://www.yahoo.com">Yahoo!</a>
</body>
How can a web page have links?
One solution is to put the link in a block element.
<body>
<p><a href="http://www.yahoo.com">Yahoo!</a></p>
</body>
17
Images In XHTML
Requires an alt attribute describing the image
<p>
<img src="hamster.jpg" alt="Hamster eating carrot" />
</p>
18
XHTML Validation
Make sure your files validate!
XHTML Validation Service: http://validator.w3.org/
When fixing errors, fix the first error and then try
validating again.
For example, a single missing closing tag might be
confused for several errors.
19
Web 2.0
20
HTML/XHTML Resources
W3Schools HTML Tutorial
http://www.w3schools.com/html/default.asp
21
Cascading Style Sheets (CSS)
22
Basic CSS Rule
A CSS file contains one or more rules.
Rule syntax:
selector {
property: value;
property: value;
...
property: value;
}
23
Example
CSS:
p {
font-family: sans-serif;
background-color: yellow;
}
HTML:
<p>Can you see me now?</p>
24
Color Properties
color: color of the element's text
background-color: color that will appear behind
the element
25
Colors
Colors are defined by three numbers (from 0 to 255) representing the
amount of red, green, and blue (RGB)
ColorSchemer: http://www.colorschemer.com/online.html
26
Colors Example
h1 {
color: rgb(0,128,128);
}
h1 {
color: #008080;
}
27
More Properties: Font
28
Attaching a CSS File: <link />
<head>
<title>...</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
29
CSS Resources
CSS property references:
http://www.w3schools.com/css/css_reference.asp
http://www.tizag.com/cssT/reference.php
CSS tutorial:
http://www.tizag.com/cssT/
30