Web Programming
Web Programming
Introduction to XHTML
2-2
2. HTML processors do not even enforce the few syntax rule that do exist in HTML
3. The syntactic correctness of XHTML documents can be validated
The opening tag and its closing tag together specify a container for the content they enclose
2-3
The container and its content together are called an element If a tag has attributes, they appear between its name and the right bracket of the opening tag
Tags are suggestions to the browser, even if they are recognized by the browser
2-4
The <title> tag is used to give the document a title, which is normally displayed in the browsers window title bar (at the top of the display)
Prior to XHTML 1.1, a document could have either a body or a frameset
Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-5
<!-- greet.hmtl A trivial document --> <html xmlns = http://www.w3.org/1999/xhtml> <head> <title> Our first document </title> </head> <body> <p> Greetings from your Webmaster! </p> </body> </html>
2-6
Line breaks
The effect of the <br /> tag is the same as that of <p>, except for the blank line No closing tag!
2-7
<!-- headings.html An example to illustrate headings --> <html xmlns = http://www.w3.org/1999/xhtml> <head> <title> Headings </title> </head> <body> <h1> Aidans Airplanes (h1) </h1> <h2> The best in used airplanes (h2) </h2> <h3> "Weve got them by the hangarful" (h3) </h3> <h4> Were the guys to see for a good used airplane (h4) </h4> <h5> We offer great prices on great planes (h5) </h5> <h6> No returns, no guarantees, no refunds, all sales are final (h6) </h6> </body> </html>
2-8
Blockquotes
Content of <blockquote> To set a block of text off from the normal flow and appearance of text Browsers often indent, and sometimes italicize
2-9
The sleet in
Crete
2-10
The meta element (for search engines) Used to provide additional information about a document, with attributes, not content
2-11
2.5 Images
GIF (Graphic Interchange Format)
8-bit color (256 different colors)
Both use compression, but JPEG compression is better Images are inserted into a document with the <img /> tag with the src attribute
The alt attribute is required by XHTML
Purposes:
1. Non-graphical browsers 2. Browsers with images turned off <img src = "comets.jpg"
The <img> tag has 30 different attributes, including width and height (in pixels) Portable Network Graphics (PNG)
Relatively new Should eventually replace both gif and jpeg
Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-12
2-14
target need not be specified in the target document as being the target
Note: Relative addressing of targets is easier to maintain and more portable than absolute addressing
2-15
2-16
2-17
The link to an id must be preceded by a pound sign (#); If the id is in the same document, this target could be
<a href = "#baskets"> What about baskets? </a>
Style note: a link should blend in with the surrounding text, so reading it without taking the link should not be made less pleasant Links can have images:
<a href = "c210data.html> <img src = "smallplane.jpg" alt = "Small picture of an airplane " /> Info on C210 </a>
2-18
2.7 Lists
Unordered lists The list is the content of the <ul> tag List elements are the content of the <li> tag
<h3> Some Common Single-Engine Aircraft </h3> <ul> <li> Cessna Skyhawk </li> <li> Beechcraft Bonanza </li> <li> Piper Cherokee </li> </ul>
Ordered lists
The list is the content of the <ol> tag Each item in the display is preceded by a sequence value
2-19
2.7 Lists
(continued)
<h3> Cessna 210 Engine Starting Instructions </h3> <ol> <li> Set mixture to rich </li> <li> Set propeller to high RPM </li> <li> Set ignition switch to "BOTH" </li> <li> Set auxiliary fuel pump switch to "LOW PRIME" </li> <li> When fuel pressure reaches 2 to 2.5 PSI, push starter button </li> </ol>
Nested lists
Any type list can be nested inside any type list The nested list must be in a list item
Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-20
2.7 Lists
(continued)
2-21
2.8 Tables
A table is a matrix of cells, each possibly having content The cells can include almost any element Some cells have row or column labels and some have data A table is specified as the content of a <table> tag A border attribute in the <table> tag specifies a border between the cells
2-22
2-23
If so, the colspan attribute must be set in the <th> tag to specify that the label must span some number of columns <tr> <th colspan = "3"> Fruit Juice Drinks </th> </tr> <tr> <th> Orange </th> <th> Apple </th> <th> Screwdriver </th> </tr>
2-24
</table>
2-25
The valign attribute controls the vertical placement of the contents of a table cell
Values are top, bottom, and center (default)
valign is an attribute of <th> and <td> elements
The cellspacing attribute of <table> is used to specify the distance between cells in a table The cellpadding attribute of <table> is used to specify the spacing between the content of a cell and the inner walls of the cell
2-26
- Table Sections
- Header, body, and footer, which are the elements: thead, tbody, and tfoot - If a document has multiple tbody elements, they are separated by thicker horizontal lines
Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-27
2.9 Forms
A form is the usual way information is gotten from a browser to a server HTML has tags to create a collection of objects that implement this information gathering
The objects are called widgets (e.g., radio buttons and checkboxes)
When the Submit button of a form is clicked, the forms values are sent to the server All of the widgets, or components of a form are defined in the content of a <form> tag
The only required attribute of <form> is action, which specifies the URL of the application that is to be called when the Submit button is clicked
action = "http://www.cs.ucp.edu/cgi-bin/survey.pl"
If the form has no action, the value of action is the empty string
2-28
Widgets
Many are created with the <input> tag The type attribute of <input> specifies the kind of widget being created 1. Text
Creates a horizontal box for text input Default size is 20; it can be changed with the size attribute If more characters are entered than will fit, the box is scrolled (shifted) left
2-29
2-30
= "groceries"
3. Radio Buttons - collections of checkboxes in which only one button can be checked at a time
Every button in a radio button group MUST have the same name
2-31
Age Category <form action = ""> <p> <input type = "radio" name = "age" value = "under20" checked = "checked"> 0-19 <input type = "radio" name = "age" value = "20-35"> 20-35 <input type = "radio" name = "age" value = "36-50"> 36-50 <input type = "radio" name = "age" value = "over50"> Over 50 </p> </form>
2-32
The name attribute of <select> is required The size attribute of <select> can be included to specify the number of menu items to be displayed (the default is 1)
If size is set to > 1 or if multiple is specified, the menu is displayed as a pop-up menu
2-33
3.
Menus (continued)
Each item of a menu is specified with an <option> tag, whose pure text content (no tags) is the value of the item An <option> tag can include the selected attribute, which when assigned "selected specifies that the item is preselected
Grocery Menu - milk, bread, eggs, cheese <form action = ""> <p> With size = 1 (the default) <select name = "groceries"> <option> milk </option> <option> bread </option> <option> eggs </option> <option> cheese </option> </select> </p> </form>
Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-34
2-35
2-37
2.10 Frames
Frames are rectangular sections of the display window, each of which can display a different document Because frames are no longer part of XHTML, you cannot validate a document that includes frames The <frameset> tag specifies the number of frames and their layout in the window
<frameset> takes the place of <body>
Cannot have both! <frameset> must have either a rows attribute or a cols attribute, or both (usually the case) Default is 1 The possible values for rows and cols are numbers, percentages, and asterisks A number value specifies the row height in pixels - Not terribly useful! A percentage specifies the percentage of total window height for the row - Very useful!
2-38
The <frame> tag specifies the content of a frame The first <frame> tag in a <frameset> specifies the content of the first frame, etc.
Row-major order is used Frame content is specified with the src attribute Without a src attribute, the frame will be empty (such a frame CANNOT be filled later)
If <frameset> has fewer <frame> tags than frames, the extra frames are empty
Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-39
If a name attribute is included, the content of the frame can be changed later (by selection of a link in some other frame)
SHOW frames.html
2-40
2-41
2-42