CSC 551: Web Programming Spring 2004: Basic HTML
CSC 551: Web Programming Spring 2004: Basic HTML
CSC 551: Web Programming Spring 2004: Basic HTML
Basic HTML
hypertext tags & elements text formatting lists, hyperlinks, images tables, frames
HTML 2.0 (IETF, 1994): tried to standardize these & other features, but late HTML 3.2 (W3C, 1996): attempted to unify into a single standard HTML 4.0 (W3C, 1997): current standard
but didn't address newer technologies like Java applets & streaming video attempted to map out future directions for HTML, not just react to vendors
XHTML 1.0 (W3C, 2000): HTML 4.01 modified to conform to XML standards
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,
HTML documents begin and end with <html> and </html> tags Comments appear between <!-- and --> HEAD section enclosed between <head> and </head>
<head> <title>Title for Page</title> </head> <body> Text that appears in the page </body> </html>
Text layout
<html> <!-- Dave Reed page02.html <!-- Demo web page <head> <title>Text Layout</title> </head> <body> <p> This is a paragraph of text<br/> made up of two lines. </p> <p> This is another paragraph with a GAP between some of the words. </p> <p> This paragraph is<br/> indented on the first line<br/> but not on subsequent lines. </p> </body> 1/16/04 --> -->
for the most part, layout of the text must be left to the browser
every sequence of whitespace is interpreted as a single space browser automatically wraps the text to fit the window size
</html>
<head> <title>Blocks of Text</title> </head> <body> <h1>Major heading 1</h1> <p> Here is some text. </p> <h2>Subheading</h2> <p> Here is some subtext. </p> <hr/> <h1>Major heading 2</h1> <p> Here is some more text. </p> </body>
bold heading
</html>
Aligning text
<html> <!-- Dave Reed page04.html <!-- Demo web page 1/16/04 --> --> <head> <title>Text Alignment</title> </head> <body> <h1 style="text-align:center">Centered Heading</h1> <p> Here is some left-justified text (which is the default in HTML). </p> <p style="text-align:center"> Here is some centered text. </p> <div style="text-align:right"> <h2>Right-justified Heading</h2> <p>Here is some right-justified text.</p> </div> </body> </html>
Text styles
<html> <!-- Dave Reed page05.html <!-- Demo web page <head> <title>Text Styles</title> </head> <body> <p> Text can be emphasized using <b>bold</b>, <i>italics</i>, or even <big>resizing</big>. <br/> The typewriter font is good for displaying code: <tt>sum = sum + i;</tt> <br /> And remember: <span style="color:red"> <small>2<sup>10</sup></small> = 1024</span> </p> </body> </html>
<b> </b> specify bold <i> </i> specify italics <tt> </tt> specify typewriter-like
for paragraphs
<head> <title>More Text Grouping</title> </head> <body> <p> <tt><pre> for (i = 0; i < 10; i++) { sum = sum + i; } </pre></tt> </p> <p> Eagleson's Law states that: <blockquote> Any code of your own that you haven't looked at for six or more months might as well have been written by someone else. </blockquote> </p> </body>
useful for code or whenever you want text to fit a specific layout
<blockquote></blockquote>
</html>
Lists
<html> <!-- Dave Reed page07.html 1/16/04 --> <head> <title>Simple Lists</title> </head> <body> <p> <ol> <li>First thing. <li>Second thing. <li>Third thing. </ol> </p> <p> <dl> <dt>HTML <dd>HyperText Markup Language <dt>HTTP <dd>HyperText Transfer Protocol </dl> </p> </body> </html>
can set type of ordering, start index <ul></ul> specifies unordered list
<dl></dl> specifies a definition list <dt> identifies each term <dd> identifies its definition view page in browser
12
Hyperlinks
<html> <!-- Dave Reed page08.html 1/16/04 -->
<head> <title>Hyperlinks</title> </head> <body> <p> <a href="http://www.creighton.edu"> Creighton University</a> <br> <a href="page07.html" target="_blank"> Open page07 in a new window</a> </p> </body> </html>
13
Hyperlinks (cont.)
<html> <!-- Dave Reed page09.html 1/16/04 --> <head> <title>Internal Links in a Page</title> </head> <body> <p align="center"> [ <a href="#HTML">HTML</a> | <a href="#HTTP">HTTP</a> | <a href="#IP">IP</a> | <a href="#TCP">TCP</a> ] </p> <p> Computer acronyms: <dl> <a name="HTML"></a><dt>HTML <dd>HyperText Markup Language <a name="HTTP"></a><dt>HTTP <dd>HyperText Transfer Protocol <a name="IP"></a><dt>IP <dd>Internet Protocol <a name="TCP"></a><dt>TCP <dd>Transfer Control Protocol </p> </body> </html>
for long documents, you can even have links to other locations in that document
<a name="ident"></a> where ident is a variable for identifying this location <a href="#ident"></a> will then jump to that location within the file <a href="URL#ident"></a> can jump into the middle of another file just as easily
14
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
<img src="filename" alt="alternate text" /> 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> </html>
15
16
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
page11.html
1/16/04 -->
<head> <title>Tables</title> </head> <body> <table> <tr> <td>foo</td> <td>bar</td> </tr> <tr> <td>bizbaz</td> <td>booboo</td> </tr> </table> </body> </html>
element
<tr></tr> specify a row in the table
17
Layout in a table
<html> <!-- Dave Reed page12.html 1/16/04 -->
<head> <title>Table Layout</title> </head> <body> <table border=1> <tr align="center"> <td>foo<br>foo</td> <td valign="top">bar</td> </tr> <tr> <td>bizbaz</td> <td>booboo</td> </tr> </table> </body> </html>
Table width
<html> <!-- Dave Reed page13.html 1/16/04 -->
<head> <title>Table Width</title> </head> <body> <table width="100%"> <tr> <td>left-most <td align="right">right-most</td> </tr> </table> </body> </html>
by default, the table is sized to fit the data can override & specify the width of a table relative to the page
<table width="60%">
useful for page footer set table width to 100% 1st column: left-justified 2nd column: right-justified
19
can control the space between cells & margins within cells
<table cellspacing=5> <table cellpadding=5>
<head> <title>Table Formatting</title> </head> <body> <table border=1 cellspacing=4 cellpadding=8> <tr> <th>HEAD1</th> <th>HEAD2</th> <th>HEAD3</th> </tr> <tr> <td>one</td> <td>two</td> <td>three</td> </tr> <tr> <td rowspan=2 align="center"> four </td> <td colspan=2 align="center"> five </td> </tr> <tr> <td> six </td> <td> seven </td> </tr> </table> </body> </html>
20
21
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
<frameset cols="50%,50%">
page15.html 1/16/03 -->
or, horizontally
<frameset rows="30%,*,*">
Frame controversy
frames are probably the most controversial HTML feature
some people love them, some people hate them
23
Menu frame
to create a menu, need to be able to direct links to the main frame
name the frames in the FRAMESET specify the frame name as TARGET in the link specify _top as target to return to top level of browser
<html> <!-- Dave Reed page16.html 1/16/04 --> <html> <!-- Dave Reed menu16.html 1/16/04 --> <head> <title>Menu of Demos</title> </head> <body> Links to demo pages <p> <a href="page01.html" target="main">Demo 1</a><br/> <a href="page02.html" target ="main">Demo 2</a><br/> <a href="page03.html" target ="main"> Demo 3</a><br/> <a href="page04.html" target ="main"> Demo 4</a><br/> <a href="page05.html" target ="main"> Demo 5</a><br/> <a href="page06.html" target ="main"> Demo 6</a><br/> <a href="http://www.creighton.edu" target="_top" >Creighton</a> </p> </body> </html>
<head> <title>Demo Browser</title> </head> <frameset cols="30%,*"> <frame src="menu16.html" name="menu"> <frame src="page01.html" name="main"> </frameset> </html>
24
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
lower-level style sheets can override higher-level style sheets
25
Using the style attribute, can specify presentation style for a single HTML element
within tag, list sequence of property:value pairs
font-family:Courier,monospace font-style:italic font-weight:bold font-size:12pt font-size:large font-size:larger color:red color:#000080 background-color:white text-decoration:underline text-decoration:none text-align:left text-align:center text-align:right text-align:justify vertical-align:top vertical-align:middle vertical-align:bottom text-indent:5em text-indent:0.2in
26
<head> <title>Inline Style Sheets</title> </head> <body> <p style="font-family:Arial,sans-serif; text-align:right">This is a right-justified paragraph in a sans serif font (preferably Arial), with some <span style="color:green">green text</span>. </p> <p>And <a style="color:red; text-decoration:none; font-size:larger;" href="page01.html">here</a> is a formatted link. </p> </body> </html>
<head> <title>Inline Style Sheets</title> </head> <body> <p>Here is an image <img src="reed.gif" alt="Dave Reed" style="margin-left:0.3in; margin-right:0.3in; vertical-align:middle; border-style:double; border-color:yellow"> embedded in text. </p> <ol style="list-style-type:upper-alpha"> <li> one thing <li> or another <ul style="list-style-type:square; whitespace:pre"> <li> with this <li> or that </ul> </ol> </body> </html>
27
28
alternatively, document style sheets allow for a clean separation of content and presentation
style definitions are placed in the HEAD of the page (within STYLE tags)
can apply to all elements, or a subclass of elements, throughout the page
29
<head> <title>Document Style Sheets</title> <style type="text/css"> h1 {color:blue; text-align:center} p.indented {text-indent:0.2in} </style> </head> <body> <h1>Centered Title</h1> <p class="indented">This paragraph will have the first line indented, but subsequent lines will be flush.</p> <p>This paragraph will not be indented. </p> <h1>The End</h1> </body> </html>
document style sheets ensure that similar elements are formatted similarly
can even define subclasses of elements and specify formatting
p.indented defines subclass of
paragraphs
30
document style sheets are especially useful in formatting tables effectively separates content from presentation what if you wanted to rightjustify the column of numbers? what if you changed your mind?
31
Pseudo-elements
<html> <!-- Dave Reed page22.html 1/16/04 --> <head> <title>Title for Page</title> <style type="text/css"> a {color : red; text-decoration : none; font-size : larger} a:visited {color : black} a:active {color : orange} a:hover {color : blue} p:first-letter {font-size : large; color : white; background-color : darkblue} </style> </head> <body> <p>Welcome to my Web page. I am so happy you are here. </p> <p>Be sure to visit <a href="http://www.cnn.com">CNN</a> for late-breaking news. </p> </body> </html>
Danger : changing the look of familiar elements is confusing Careful : current browsers do not support all CSS2 features
view page in browser
32
33
<head> <title>Title for Page</title> <link rel="stylesheet" type="text/css" href="myStyle.css" title="myStyle"> </head> <body> <h1>Centered Title</h1> <p class="indented">This paragraph will have the first line indented, but subsequent lines will be flush.</p>
ideally, the developer(s) of a Web site would place all formatting options in an external style sheet all Web pages link to that same style sheet for a uniform look
simplifies Web pages since only need to specify structure/content tags
34
e.g., bright background images can make text hard to read e.g., the use of clickable images instead of buttons or links can slow access
e.g., font size may be adjusted by viewer, window constrained
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
35