Hypertext & HTML: Static
Hypertext & HTML: Static
for most users who want to develop basic, static Web pages, these are fine
2
Structural elements
an HTML document has two main structural elements
HEAD contains setup information for the browser & the Web page
e.g., the title for the browser window, style definitions, JavaScript code, …
BODY contains the actual content to be displayed in the Web page
<html>
<!-- Dave Reed page01.html 1/16/04 --> HTML documents begin and end with <html>
<!-- Demo web page --> and </html> tags
<head>
Comments appear between <!-- and -->
<title>Title for Page</title>
</head>
HEAD section enclosed between <head>
<body> and </head>
Text that appears in the page
</body>
BODY section enclosed between <body>
</html> and </body>
3
Text layout
<html>
for the most part, layout of the text
<head>
<title>Text Layout</title>
must be left to the browser
</head> every sequence of whitespace is
interpreted as a single space
<body> browser automatically wraps the text to
<p>
This is a paragraph of text<br/>
fit the window size
made up of two lines.
</p>
</html>
</html>
<a href="URL"
target="_blank">…</a>
view page in browser
causes the page to be loaded in a new
window
10
Hyperlinks (cont.)
<html>
<!-- Dave Reed page09.html 1/16/04 -->
for long documents, you can even
have links to other locations in that
<head>
<title>Internal Links in a Page</title>
document
</head>
<a name="ident">…</a>
<body>
<p align="center"> where ident is a variable for identifying
[ <a href="#HTML">HTML</a> | this location
<a href="#HTTP">HTTP</a> |
<a href="#IP">IP</a> |
<a href="#TCP">TCP</a> ]
</p> <a href="#ident">…</a>
<p>
Computer acronyms: will then jump to that location within the
<dl> file
<a name="HTML"></a><dt>HTML
<dd>HyperText Markup Language
<a name="HTTP"></a><dt>HTTP <a href="URL#ident">…</a>
<dd>HyperText Transfer Protocol
<a name="IP"></a><dt>IP can jump into the middle of another file
<dd>Internet Protocol just as easily
<a name="TCP"></a><dt>TCP
<dd>Transfer Control Protocol
</p>
</body>
</html> view page in browser 11
Images
can include images using IMG
by default, browsers can display GIF and JPEG files
other image formats may require plug-in applications for display
again, if file is to be accessed over the Web, must start with http:// (if not, will assume local file)
<html>
<!-- Dave Reed page10.html 1/16/04 -->
<head>
<title>Images</title>
</head>
<body>
<div style="text-align:center">
<img src="http://www.creighton.edu/~davereed/Images/reed.gif"
alt="Dave Reed" />
<p>Dave Reed</p>
</div>
</body> view page in brow
</html> ser 12
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>
<!-- Dave Reed page11.html 1/16/04 -->
<head>
<title>Tables</title> <table>…</table> specify a table
</head>
element
<body>
<table> <tr>…</tr> specify a row in the table
<tr>
<td>foo</td> <td>bar</td>
</tr> <td>…</td> specify table data (i.e., each
<tr> column entry in the table)
<td>bizbaz</td> <td>booboo</td>
</tr>
</table>
</body>
</html> view page in browser 13
Layout in a table
can have a border on tables using
<html>
<!-- Dave Reed page12.html 1/16/04 --> the BORDER attribute
<head> <table border=1>
<title>Table Layout</title>
</head> increasing the number makes the border thicker
<body>
<table border=1>
can control the horizontal & vertical
<tr align="center"> layout within cells
<td>foo<br>foo</td>
<td valign="top">bar</td> <td align="center">
</tr>
<tr> <td align="right">
<td>bizbaz</td>
<td>booboo</td> <td valign="top">
</tr>
</table> <td valign="bottom">
</body>
</html>
can apply layout to an entire row
view page in browser
<tr align="center">
<tr valign="top">
14
Table width
<html>
<!-- Dave Reed page13.html 1/16/04 --> by default, the table is sized to fit
<head>
the data
<title>Table Width</title>
</head>
can override & specify the width of a
<body>
<table width="100%">
table relative to the page
<tr> <table width="60%">
<td>left-most
<td align="right">right-most</td>
</tr>
</table>
</body>
useful for page footer –
</html> set table width to 100%
1st column: left-justified
2nd column: right-justified
view page in browser
15
Other table options
<html> can control the space between
<!-- Dave Reed page14.html 1/16/04 -->
cells & margins within cells
<head> <table cellspacing=5>
<title>Table Formatting</title>
</head> <table cellpadding=5>
<body>
<table border=1 cellspacing=4 cellpadding=8>
can add headings
<tr> <th> is similar to <td> but displays
<th>HEAD1</th> <th>HEAD2</th> <th>HEAD3</th> heading centered in bold
</tr>
<tr>
<td>one</td> <td>two</td> <td>three</td> can have data that spans more
</tr> than one column
<tr>
<td rowspan=2 align="center"> four </td> <td colspan=2>
<td colspan=2 align="center"> five </td>
</tr>
<tr> similarly, can span more than one
<td> six </td> <td> seven </td> row
</tr>
</table> <td rowspan=2>
</body>
</html>
view page in browser
16
Example Web page revisited
office hours are aligned, with "Office hours:" to the left (2-column table)
17
Frames
frames provide the ability to split the screen into independent pages
must define a FRAMESET that specifies the layout of the pages
actual pages to be displayed must be in separate files
19
Menu frame
to create a menu, need to be able to <html>
<!-- Dave Reed menu16.html 1/16/04 -->
direct links to the main frame <head>
name the frames in the FRAMESET <title>Menu of Demos</title>
specify the frame name as TARGET </head>
in the link
<body>
specify _top as target to return to Links to demo pages
top level of browser
<p>
<a href="page01.html"
<html> target="main">Demo 1</a><br/>
<!-- Dave Reed page16.html 1/16/04 --> <a href="page02.html"
target ="main">Demo 2</a><br/>
<head> <a href="page03.html"
<title>Demo Browser</title> target ="main"> Demo 3</a><br/>
</head> <a href="page04.html"
target ="main"> Demo 4</a><br/>
<frameset cols="30%,*"> <a href="page05.html"
<frame src="menu16.html" name="menu"> target ="main"> Demo 5</a><br/>
<frame src="page01.html" name="main"> <a href="page06.html"
</frameset> target ="main"> Demo 6</a><br/>
<a href="http://www.creighton.edu"
</html> target="_top" >Creighton</a>
</p>
view page in browser </body>
</html> 20
Content vs. presentation
most HTML tags define content type, independent of presentation
exceptions?
HTML style sheets are known as Cascading Style Sheets, since can be defined at
three different levels
1. inline style sheets apply to the content of a single HTML element
2. document style sheets apply to the whole BODY of a document
3. external style sheets can be linked and applied to numerous documents
21
Inline style sheets Using the style attribute, can
specify presentation style for a
<html>
<!-- Dave Reed page17.html 1/16/04 -->
single HTML element
<head> within tag, list sequence of
<title>Inline Style Sheets</title> property:value pairs
</head>
font-family:Courier,monospace
<body>
font-style:italic
<p style="font-family:Arial,sans-serif;
text-align:right">This is a font-weight:bold
right-justified paragraph in a sans serif font-size:12pt font-size:large font-size:larger
font (preferably Arial), with some
<span style="color:green">green text</span>. color:red color:#000080
</p> background-color:white
<p>And <a style="color:red;
text-decoration:underline
text-decoration:none;
font-size:larger;"
text-decoration:none
href="page01.html">here</a> text-align:left text-align:center
is a formatted link. text-align:right text-align:justify
</p> vertical-align:top vertical-align:middle
</body> vertical-align:bottom
</html>
text-indent:5em text-indent:0.2in
view page in browser
22
Inline style sheets (cont.)
<html>
<!-- Dave Reed page18.html 1/16/04 --> more style properties & values
<head>
<title>Inline Style Sheets</title>
margin-left:0.1in margin-right:5%
</head>
margin:3em
<body> padding-top:0.1in padding-bottom:5%
<p>Here is an image padding:3em
<img src="reed.gif" alt="Dave Reed"
style="margin-left:0.3in;
margin-right:0.3in; border-width:thin border-width:thick
vertical-align:middle; border-width:5
border-style:double; border-color:red
border-color:yellow"> border-style:dashed border-style:dotted
embedded in text. border-style:double border-style:none
</p>
<ol style="list-style-type:upper-alpha">
whitespace:pre
<li> one thing
<li> or another list-style-type:square
<ul style="list-style-type:square; list-style-type:decimal
whitespace:pre"> list-style-type:lower-alpha
<li> with this list-style-type:upper-roman
<li> or that
</ul>
</ol>
</body> 23
</html> view page in browser
Inline style sheets (cont.)
<html>
<!-- Dave Reed page19.html 1/16/04 --> style sheets can be applied to
<head> tables for interesting effects
<title> Inline Style Sheets </title>
</head>
<body>
<table style="font-family:Arial,sans-serif">
<caption style="color:red;
font-style:italic;
text-decoration:underline">
Student data. </caption>
<tr style="background-color:red">
<th> name </th> <th> age </th>
</tr>
<tr>
<td> Chris Smith </td> <td> 19 </td>
</tr>
<tr>
<td> Pat Jones </td> <td> 20 </td>
</tr>
<tr>
<td> Doogie Howser </td> <td> 9 </td>
</tr>
</table>
</body>
</html>
view page in browser
24
Document style sheets
inline style sheets apply to individual elements in the page
can lead to inconsistencies as similar elements are formatted differently
e.g., might like for all H1 elements to be centered
25
Document style sheets
<html>
<!-- Dave Reed page20.html 1/16/04 --> document style sheets ensure that
<head> similar elements are formatted
<title>Document Style Sheets</title>
<style type="text/css">
similarly
h1 {color:blue; can even define subclasses of
text-align:center} elements and specify formatting
p.indented {text-indent:0.2in}
</style> p.indented defines subclass of
</head> paragraphs
• inherits all defaults of <p>
<body> • adds new features
<h1>Centered Title</h1>
to specify this newly defined class, place
<p class="indented">This paragraph will
have the first line indented, but
class="ID" attribute in tag
subsequent lines will be flush.</p>
</body>
</html> view page in browser 26
Document style sheets (cont.)
<html>
<!-- Dave Reed page21.html 1/16/04 -->
document style sheets are
<head>
<title> Inline Style Sheets </title> especially useful in
<style type="text/css">
table {font-family:Arial,sans-serif}
formatting tables
caption {color:red;
font-style:italic;
text-decoration:underline}
th {background-color:red}
effectively separates
</style> content from presentation
</head>
<body>
<table>
<caption> Student data. </caption>
what if you wanted to right-
<tr><th> name </th> <th> age</th></tr> justify the column of
<tr><td> Chris Smith </td> <td> 19 </td></tr>
<tr><td> Pat Jones </td> <td> 20 </td></tr> numbers?
<tr><td> Doogie Howser </td> <td> 9 </td></tr>
</table>
</body> what if you changed your
</html>
mind?
view page in browser
27
Pseudo-elements
<html>
<!-- Dave Reed page22.html 1/16/04 --> pseudo-elements are used to
address sub-parts of elements
<head>
<title>Title for Page</title>
<style type="text/css">
can specify appearance of link in
a {color : red; various states
:visited :active :hover
text-decoration : none;
font-size : larger} can specify format of first line in page
a:visited {color : black} or paragraph
a:active {color : orange} :first-line
a:hover {color : blue}
p:first-letter {font-size : large; can specify format of first letter in
color : white; page or paragraph
background-color : darkblue} :first-letter
</style>
</head>
Danger : changing the look of
<body>
<p>Welcome to my Web page. I am so familiar elements is confusing
happy you are here.
</p>
<p>Be sure to visit Careful : current browsers do not
<a href="http://www.cnn.com">CNN</a> support all CSS2 features
for late-breaking news.
</p>
</body> view page in browser 28
</html>
External style sheets
modularity is key to the development and reuse of software
design/implement/test useful routines and classes
package and make available for reuse
29
Modularity & style sheets
<html> <!-- myStyle.css Dave Reed 1/16/04 -->
<!-- Dave Reed page23.html 1/16/04 -->
h1 {color : blue; text-align : center}
p.indented {text-indent:0.2in}
<head>
<title>Title for Page</title>
<link rel="stylesheet"
type="text/css"
href="myStyle.css"
title="myStyle">
ideally, the developer(s) of a Web site
</head> would place all formatting options in an
<body> external style sheet
<h1>Centered Title</h1>
<p class="indented">This paragraph will all Web pages link to that same style
have the first line indented, but
subsequent lines will be flush.</p> sheet for a uniform look
<p>This paragraph will not be indented.
</p> simplifies Web pages since only need to
specify structure/content tags
<h1>The End</h1>
</body>
</html>
view page in browser 30
Web rules of thumb
HTML provides for lots of neat features,
but just because you can add a feature doesn't mean you should!
don't add features that distract from the content of the page
use color & fonts sparingly and be careful how elements fit together
e.g, no purple text on a pink background, no weird fonts
break large document into smaller or provide a menu (either internal or frame)
stick to standard features and test using both IE and Netscape
utilize style sheets to make changes easy & ensure consistency
31