User Tools

Site Tools


eg-259:xhtml

This is an old revision of the document!


~~SLIDESHOW~~

We recommend that you view this document in slideshow mode first then go back and read the notes.

The Structural Layer

Origins and Evolution of HTML

  • HTML was defined with SGML
  • Original intent of HTML: General layout of documents that could be displayed by a wide variety of computers
  • Recent versions:
    • HTML 4.0 – 1997
    • HTML 4.01 – 1999
    • XHTML 1.0 – 2000
    • XHTML 1.1 – 2001
    • XHTML 2.0 and HTML 5 – under development (in 2008)
    • Development of XHTML 2 ceased in 2010. HTML5 became mainstream in 2011.

More about the versions

  • HTML 4.0 – 1997
    • Introduced many new features and deprecated

many older features

  • HTML 4.01 – 1999
    • A cleanup of 4.0
  • XHTML 1.0 – 2000
    • Just 4.01 defined using XML, instead of SGML
  • XHTML 1.1 – 2001
    • Modularized 1.0, and drops frames
    • We'll stick to 1.1 and avoid frames
  • XHTML 2 and HTML 5 – under development as of 2008, some browser support planned for Firefox 3.1

Reasons to use XHTML, rather than HTML

  • HTML has lax syntax rules, leading to sloppy and sometimes ambiguous documents
  • HTML processors do not even enforce the few syntax rule that do exist in HTML
  • XHTML syntax is stricter, leading to clean and clear documents in a standard form
  • The syntactic correctness of XHTML documents can be validated
  • HTML5 allows both the less strict conventions of HTML5 and the stricter XHTML syntax.
  • To avoid relearning what you already know, we will continue to use the XHTML syntax except where HTML5 syntax is simpler to understand.

Basic Syntax

  • Elements are defined by tags (markers) which act as containers for content: e.g. <name> content </name>.
  • The opening tag and its closing tag together specify a container for the content they enclose
  • Not all elements have content: if a tag has no content, its form is <name />
  • 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: e.g <element [name=“value”]*> content </element>
  • Comment form: <!- … –>

Notes

  • Tag format:
    • Opening tag: <name>
    • Closing tag: </name>
  • Attributes:
    • in the example [name=“value”]* means that an attribute – defined as a name followed by = followed by a quoted value – can appear 0 or more times in an element's opening tag. Thus attributes are optional, but when they appear they must have the form name=“value”. Furthermore if there are attributes, there can be any number of attributes.
  • Browsers ignore comments, unrecognizable tags, line breaks, multiple spaces, and tabs
  • Even if they are recognized by the browser, tags are only suggestions to the browser.

Standard HTML5 Document Structure

  • Every HTML5 document begins with the simple DOCTYPE declaration:
      <!DOCTYPE html>
  • The elements <html>, <head>, <title>, and <body> are required in every document
  • The whole document must have <html> as its root
  • For compatibility with XHTML specifications the html element may use the xmlns attribute:
      <html lang="en">

The language of the document is declared in the lang attribute. This is useful for browsers who may be visiting your site from another non-english speaking country (particular if that country uses a different character set).

A Minimal XHTML Document

  • A document consists of a head and a body
  • The <title> element is used to give the document a title
  • A <meta> element that specifies the character encoding used for the document should be included
  • Text is normally placed in paragraph elements (<p>) in the body of the document
  • W3C HTML Validation Service http://validator.w3.org/file-upload.html

Notes

  • The content of the <title> element is normally displayed in the browser's window title bar (at the top of the display).
  • Prior to XHTML 1.1, a document could have either a body or a frameset
  • A common setting for the <meta> tag is utf-8 defined like this
<meta charset="utf-8" />
  • Paragraph Elements
    • The <p> tag breaks the current line and inserts a blank line – the new line gets the beginning of the content of the paragraph
    • The browser puts as many words of the paragraph's content as will fit in each line

An Example Minimal Valid Document

first document
<!DOCTYPE html>
<!-- example.html: A trivial document -->
<html lang="en">
  <head> 
    <meta charset="utf-8" />
    <title> Our first document </title>
  </head>
  <body>
    <p> 
      Greetings from your Webmaster!
    </p>
  </body>
</html>
  • I recommend that you download a copy of this document (example.html) and use it as a template.

[ Jump to CSS ]

Day-to-day Markup

Line Breaks

  • The effect of the <br /> tag is the same as that of <p>, except for the blank line
  • An example of paragraphs and line breaks:
      <p>On the plains of hesitation</p> <p> bleach the
      bones of countless millions  <br />
      who, at the dawn of victory <br /> sat down
      to wait, and waiting, died.</p>

Notes and Details of the Example

  • Note that <br /> has no closing tag!
  • The example of paragraphs and line breaks: line-breaks.html
example of paragraphs and line breaks
<!DOCTYPE html>
<!-- line-breaks.html
     An Example of Paragraphs and Line Breaks 
-->
<html lang="en">
  <head> 
      <meta charset="utf-8" />
      <title> Paragraphs and Line Breaks </title>
  </head>
  <body>
     <p>On the plains of hesitation</p> <p> bleach the
      bones of countless millions  <br />
      who, at the dawn of victory <br /> sat down
      to wait, and waiting, died.</p>
   </body>
</html>
  • Typical display:

<html> <p>On the plains of hesitation</p> <p> bleach the bones of countless millions <br /> who, at the dawn of victory <br /> sat down to wait, and waiting, died.</p> </html>

Headings

  • Six sizes, 1—6, specified with <h1> to <h6>
  • 1, 2, and 3 use font sizes that are larger than the default font size
  • 4 uses the default size
  • 5 and 6 use smaller font sizes
  • An example of headings: headings.html

  • Code for the Example
example to illustrate headings
<!DOCTYPE html>
<!-- headings.html
     An example to illustrate headings
-->
<html lang="en">
  <head> 
    <meta charset="utf-8" />
    <title> Headings </title>
  </head>
  <body>
    <h1> Aidan's Airplanes (h1) </h1>
    <h2> The best in used airplanes (h2) </h2>
    <h3> "We've got them by the hangarful" (h3)
    </h3>
    <h4> We're 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>
  • Typical Display

An example of the use of the headings elements

Quotations

  • Content of <blockquote>
  • To set a block of text off from the normal flow and appearance of text
  • Browsers often indent, and sometimes italicize
  • Example: blockquote.html

Code for the Example

example to illustrate a blockquote
<!DOCTYPE html>
<!-- blockquote.html
An example to illustrate a blockquote
-->
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title> Blockquotes </title>
    </head>
    <body>
        <p>
            Abraham Lincoln is generally regarded as one of the greatest
            presidents of the U.S. His most famous speech was delivered
            in Gettysburg, Pennsylvania, during the Civil War. This
            speech began with
        </p>
        <blockquote>
            <p>
                "Fourscore and seven years ago our fathers brought forth on
                this continent, a new nation, conceived in Liberty, and
                dedicated to the proposition that all men are created equal.
            </p>
            <p>
                Now we are engaged in a great civil war, testing whether
                that nation or any nation so conceived and so dedicated,
                can long endure."
            </p>
        </blockquote>
        <p>
            Whatever one's opinion of Lincoln, no one can deny the
            enormous and lasting effect he had on the U.S.
        </p>
    </body>
</html>

Typical Display

An example of the use of the blockquote element

Font Styles and Sizes

<small> The </small> <big> sleet <big> in <big> <i> Crete
</i><br /> lies </big> <b> completely </b> </big>
in </big> the <tt>street</tt>

<html> <small> The </small> <big> sleet <big> in <big> <i> Crete </i><br /> lies </big> <b> completely </b> </big> in </big> the <tt>street</tt> </html>


  • Can be nested
    • Boldface – <b>
    • Italics – <i>
    • Larger – <big>
    • Smaller – <small>
    • Monospace – <tt>

These tags are not affected if they appear in the content of a <blockquote>, unless there is a conflict (e.g., italics)

Subscripts and Superscripts

  • Subscripts with sub
  • Superscripts with sup

<html> x23 </html>

x<sub>2</sub><sup>3</sup>

Very Important Note

  • All of this font size and font style stuff can (and should) be done with style sheets, but the tags are not yet deprecated
  • Block elements CANNOT be nested in in-line elements

Character Entities

Needed to enter certain special characters into a web page

Char Entity Meaning
& &amp; Ampersand
< &lt; Less than
> &gt; Greater than
&quot; Double quote
' &apos; Single quote
¼ &frac14; One quarter
½ &frac12; One half
¾ &frac34; Three quarters
? &deg; Degree
(space) &nbsp; Non-breaking space

Notes:

The first four character entities are needed to display the characters that are used by XHTML elements and attributes. For example to display <p class=“greeting”>Hello World!</p> in a web page we have to enter &lt;p class=&quot;greeting&quot;&gt;Hello World!&lt;/p&gt; and to display the & symbol we have to use &amp;amp;. This can make the display of HTML code in a web page quite a challenge!

For a full list of the 252 usable character entities see 1 and 2.

Other Elements

Horizontal Rules and Meta Tags

  • Horizontal rules
    • <hr /> draws a line across the display, after a line break
  • The meta element (for search engines)
    • Used to provide additional information about a document, with attributes, not content

Images

  • GIF (Graphic Interchange Format)
  • JPEG (Joint Photographic Experts Group)
  • Both use compression, but JPEG compression is better
  • Portable Network Graphics (PNG)

  • GIF – 8-bit color (256 different colors)
  • JPEG – 24-bit color (16 million different colors)
    • Both use compression, but JPEG compression is better
  • PNG
    • Relatively new
    • Should eventually replace both GIF and JPEG

Images – Markup

<img src = "comets.jpg"
     alt = "Picture of comets" />
  • Images are inserted into a document with the <img /> tag with the src attribute
  • The alt attribute is required by XHTML
  • The <img> tag has 30 different attributes, including width and height
  • Example Document: image.html

  • Purpose of the alt attribute:
    1. Non-graphical browsers
    2. Browsers with images turned off
    3. Accessibility, e.g. screen readers

Code for the Example

example to illustrate an image
<!DOCTYPE html>
 
<!-- image.html
     An example to illustrate an image
     -->
<html lang="en">
  <head> 
      <meta charset="utf-8" />
      <title> Images </title>
  </head>
  <body>
    <h1> Aidan's Airplanes </h1>
    <h2> The best in used airplanes </h2>
    <h3> "We've got them by the hangarful" </h3>
    <h2> Special of the month </h2>
    <p>
      1960 Cessna 210 <br />
      577 hours since major engine overhaul<br />
      1022 hours since prop overhaul <br /><br />
<img src = "c210new.jpg"  alt = "Picture of a Cessna 210" />
      <br />
      Buy this fine airplane today at a remarkably low price
      <br />
      Call 999-555-1111 today!
    </p>
  </body>
</html>

Typical Display

An example of a document with an image

  • Hypertext is the essence of the Web!
  • A link is specified with the href (hypertext reference) attribute of <a> (the anchor tag)
  • The content of <a> is the visual link in the document
  • If the target is a whole document (not the one in which the link appears), the target need not be specified in the target document as being the target
  • Example: link.html

Notes

Relative addressing of targets is easier to maintain and more portable than absolute addressing

Code for the Example

example to illustrate a link
<!DOCTYPE html>
 
<!-- link.html
     An example to illustrate a link
     -->
<html lang="en">
  <head> 
      <meta charset="utf-8" />
      <title> A link </title>
  </head>
  <body>
    <h1> Aidan's Airplanes </h1>
    <h2> The best in used airplanes </h2>
    <h3> "We've got them by the hangarful" </h3>
    <h2> Special of the month </h2>
    <p>
      1960 Cessna 210 <br />
      <a href = "C210data.html"> Information on the Cessna 210 </a>
    </p>
  </body>
</html>

Typical Display

An example of a document with links

Link Target

The Link Target is C210data.html

example to illustrate the target of a link
<!DOCTYPE html>
 
<!-- C210data.html
     An example to illustrate the target of a link
     -->
<html lang="en">
  <head> 
      <meta charset="utf-8" />
      <title> 1960 Cessna C210 </title>
  </head>
  <body>
    <h1> 1960 Cessna 210 </h2>
    <p>
      577 hours since major engine overhaul<br />
      1022 hours since prop overhaul <br /><br />
      <img src = "c210new.jpg"  alt = "Picture of a Cessna 210" />
      <br />
      Buy this fine airplane today at a remarkably low price
      <br />
      Call 999-555-1111 today!
    </p>
  </body>
</html>

Typical Display

The Target of the Link Example

  • If the target is not at the beginning of the document, the target spot must be marked
  • Target labels can be defined in many different tags with the id attribute, as in:
      <h1 id = "baskets"> Baskets </h1>
  • 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>
  • If the target is in a different document, the document reference must be included:
      <a href = "myAd.html#baskets"> 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>

Exercises to Demonstrate Basic XHTML

  1. Create, test and validate an XHTML document for yourself. including your name, address, and e-mail address. You must include your student number, course and level. This document must use several headings and <big>, <small>, <hr />, <p> and <br /> tags.
  2. Add pictures of yourself and at least one image (e.g. of your friend, spouse, pet) to the document created in Exercise 1.
  3. Add a second document to the document created for Exercise 1 that describes part of your background, using the word background as the link content. This document should have a few paragraphs of your personal history.

More Advanced Markup

Unordered Lists

  • The list is the content of the <ul> tag
  • List elements are the content of the <li> tag: unordered.html

example to illustrate an unordered list
<!DOCTYPE html>
 
<!-- unordered.html
     An example to illustrate an unordered list
     -->
<html lang="en">
  <head> 
      <meta charset="utf-8" />
      <title> Unordered list </title>
  </head>
  <body>
    <h3> Some Common Single-Engine Aircraft </h3>
    <ul> 
      <li> Cessna Skyhawk </li>
      <li> Beechcraft Bonanza </li>
      <li> Piper Cherokee </li>
    </ul>
  </body>
</html>

Ordered lists

  • The list is the content of the <ol> tag
  • Each item in the display is preceded by a sequence value: ordered.html

example to illustrate an ordered list
<!DOCTYPE html>
 
<!-- ordered.html
     An example to illustrate an ordered list
     -->
<html lang="en">
  <head> 
      <meta charset="ut-8f" />
      <title> Ordered list </title>
  </head>
  <body>
    <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>
  </body>
</html>

Nested lists

  • Any type list can be nested inside any type list
  • The nested list must be in a list item: nested_lists.html

<!DOCTYPE html|An example to illustrate nested lists>
 
<!-- nested_lists.html
     An example to illustrate nested lists
  -->
<html lang="en">
  <head> 
      <meta charset="utf-8" />
      <title> Nested lists </title>
  </head>
  <body>
    <h3> Aircraft Types </h3>
    <ol>
      <li> General Aviation (piston-driven engines) 
        <ol>
          <li> Single-Engine Aircraft 
            <ol>
              <li> Tail wheel </li>
              <li> Tricycle </li>
            </ol> <br />
          </li>
          <li> Dual-Engine Aircraft
            <ol>
              <li> Wing-mounted engines </li>
              <li> Push-pull fuselage-mounted engines </li>
            </ol>
          </li>
	</ol> <br />
      </li>
      <li> Commercial Aviation (jet engines)
	<ol>
	  <li> Dual-Engine
	    <ol>
	      <li> Wing-mounted engines </li>
	      <li> Fuselage-mounted engines </li>
	    </ol> <br />
	  </li>
	  <li> Tri-Engine
	    <ol>
	      <li> Third engine in vertical stabilizer </li>
	      <li> Third engine in fuselage </li>
	    </ol>
	  </li>
	</ol>
      </li>
    </ol>
  </body>
</html>

Definition lists

  • For glossaries, etc.
  • List is the content of the <dl> tag
  • Terms being defined are the content of the <dt> tag
  • The definitions themselves are the content of the <dd> tag: definition.html

<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 
<!-- definition.html
     An example to illustrate definition lists
     -->
<html xmnls="http://www.w3.org/1999/xhtml" xml:lang="en">
  <head> <title> Definition lists </title>
  </head>
  <body>
    <h3> Single-Engine Cessna Airplanes </h3>
    <dl>
      <dt> 152 </dt>
      <dd> Two-place trainer </dd>
      <dt> 172 </dt>
      <dd> Smaller four-place airplane </dd>
      <dt> 182 </dt>
      <dd> Larger four-place airplane </dd>
      <dt> 210 </dt>
      <dd> Six-place airplane - high performance </dd>
    </dl>
  </body>
</html>

Exercises to Demonstrate Lists

  1. Create, test and validate an XHTML document to describe an unordered list of a typical supermarket shopping list you write. (If you've never made such a list, use your imagination).
  2. Create, test and validate an XHTML document to describe an unordered list of at least 4 countries. Each element of the list must have a nested list of at least three cities in the country.
  3. Create, test and validate an XHTML document to describe an ordered list of your five favourite movies.
  4. Modify the list of Exercise 6 to add nested, unordered lists of at least two actors and/or actresses in each of your favourite movies.

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
  • Tables are given titles with the <caption> tag, which can immediately follow <table>

Notes

  • If border is set to “border”, the browser's default-width border is used
  • The border attribute can be set to a number, which will be the border width
  • Without the border attribute, the table will have no lines!

Table Rows and Cells

  • Each row of a table is specified as the content of <tr> tag
  • The *row headings* are specified as the content of a <th> tag
  • The contents of a *data cell* is specified as the content of a <td> tag
  • An example table: table.html

<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.1//EN"
	  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 
<!-- table.html
     An example of a simple table
  -->
<html xmlns = "http://www.w3.org/1999/xhtml" xml:lang="en">
  <head> <title> A simple table </title>
  </head>
  <body>
    <table border = "border">
      <caption> Fruit Juice Drinks </caption>
      <tr>
        <th> </th>
        <th> Apple </th>
        <th> Orange </th>
        <th> Screwdriver </th>
      </tr>
      <tr>
	<th> Breakfast </th>
	<td> 0 </td>
	<td> 1 </td>
	<td> 0 </td>
      </tr>
      <tr>
	<th> Lunch </th>
	<td> 1 </td>
	<td> 0 </td>
	<td> 0 </td>
      </tr>
      <tr>
	<th> Dinner </th>
	<td> 0 </td>
	<td> 0 </td>
	<td> 1 </td>
      </tr>
    </table>
  </body>
</html>

More Table Elements and Attributes

For information on column and row spanning, cell alignment, cell spacing and padding see the notes.


Tables – colspan

  • A table can have two levels of column labels, e.g.
      <table border="border">
      <tr>
        <th colspan = "3"> Fruit Juice Drinks </th>
      </tr>
      <tr>
        <th> Orange </th>
        <th> Apple </th>
        <th> Screwdriver </th>
      </tr>
      </table>
  • If so, the colspan attribute must be set in the <th> tag to specify that the label must span some number of columns:
      <table border="border">
        <tr>
          <th colspan = "3"> Fruit Juice Drinks </th>
        </tr>
        <tr>
          <th> Apple </th>
          :
        </tr>
        :
      </table>

Tables – rowspan

  • If the rows have labels and there is a spanning column label, the upper left corner must be made larger, using rowspan, e.g.
        <table border = "border">
          <tr>
            <td rowspan = "2"> &nbsp; </td>
            <th colspan = "3"> Fruit Juice Drinks
            </th>
          </tr>
          <tr>
            <th> Apple </th>
            <th> Orange </th>
            <th> Screwdriver </th>
          </tr>
        </table>
  • Is created with:
        <table border = "border">
        <tr>
          <td rowspan = "2"> &nbsp; </td>
          <th colspan = "3"> Fruit Juice Drinks
          </th>
        </tr>
        <tr>
          <th> Apple </th>
          :
        </tr>
          :
      </table>
  • Download the colspan/rowspan example: cell_span.html. Here is the complete source code:
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 
<!-- cell_span.html
     An example to illustrate rowspan and colspan
     -->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  <head> <title> Rowspan and colspan </title>
  </head>
  <body>
<table border = "border">
      <caption> Fruit Juice Drinks and Meals </caption>
      <tr>
        <td rowspan = "2"> &nbsp; </td>
        <th colspan = "3"> Fruit Juice Drinks </th>
      </tr>
      <tr>
        <th> Apple </th>
        <th> Orange </th>
        <th> Screwdriver </th>
      </tr>
      <tr>
        <th> Breakfast </th>
        <td> 0 </td>
        <td> 1 </td>
        <td> 0 </td>
      </tr>
      <tr>
        <th> Lunch </th>
        <td> 1 </td>
        <td> 0 </td>
        <td> 0 </td>
      </tr>
      <tr>
        <th> Dinner </th>
        <td> 0 </td>
        <td> 0 </td>
        <td> 1 </td>
      </tr>
    </table>
  </body>
</html>

Tables – alignment

  • The align attribute controls the horizontal placement of the contents in a table cell
    • align is an attribute of <tr>, <th>, and <td> elements
    • Values are left, right, and center (default)
      • note the American English spelling of center.
  • The valign attribute controls the vertical placement of the contents of a table cell
    • valign is an attribute of <th> and <td> elements
    • Values are top, bottom, and center (default)
  • Example of cell alignment: cell_align.html
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 
<!-- cell_align.html
     An example to illustrate align and valign
     -->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  <head> <title> Alignment in cells </title>
  </head>
  <body>
<table border = "border">
      <caption> The align and valign attributes </caption>
      <tr align = "center">
	    <th> </th>
		<th> Column Label </th>
		<th> Another One </th>
		<th> Still Another One </th>
      </tr>
      <tr>
        <th> align </th>
        <td align = "left"> Left </th>
        <td align = "center"> Center </th>
        <td align = "right"> Right </th>
      </tr>
      <tr>
        <th> <br /> valign <br /> <br /> </th>
        <td> Default  </th>
        <td valign = "top"> Top </th>
        <td align = "bottom"> Bottom </th>
      </tr>
    </table>
  </body>
</html>

Tables – cell spacing

  • 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
  • Example: space_pad.html
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 
<!-- space_pad.html
     An example that illustrates the cellspacing and
     cellpadding table attributes
     -->
<html xmlns = "http://www.w3.org/1999/xhtml" xml:lang="en">
  <head> <title> Cell spacing and cell padding </title>
  </head>
  <body>
    <b>Table 1 (space = 10, pad = 30) </b><br /><br />
    <table border = "5"  cellspacing = "10"  cellpadding = "30">
      <tr>
        <td> Small spacing, </td>
        <td> large padding </td>
      </tr>
    </table>
    <br /><br /><br /><br />
    <b>Table 2 (space = 30, pad = 10) </b><br /><br />
    <table border = "5"  cellspacing = "30"  cellpadding = "10">
      <tr>
        <td> Large spacing, </td>
        <td> small padding </td>
      </tr>
    </table>
  </body>
</html>

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

Exercises to Demonstrate Tables

  1. Create, test and validate an XHTML document to describe a table with the following contents:
    • The columns of the table must have the headings Pine, Maple, Oak and Fir
    • The rows must have labels Average Height, Average Diameter, Typical Lifespan, and Leaf Type.
    • You can make up the data cell values.
  2. Modify, test and validate an XHTML document from Exercise 1 to add a second level column label, Tree, and a second-level row label, Characteristics.
  3. Create, test and validate an XHTML document to describe a table with columns for country, national language, capital city and population. There must be at least five countries in the table. You must include attribute specifications for cell padding and cell spacing.

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
  • For this reason we shall say no more about them in this module!
  • There is more information, and some examples, in the handout.
  • This will not be examined.

More on Frames (not examined)

  • 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!
  • An asterisk after some other specification gives the remainder of the height of the window
  • Examples:
          <frameset rows = "150, 200, 300">
 
          <frameset rows = "25%, 50%, 25%">
 
          <frameset rows = "50%, 20%, *" >
 
          <frameset rows = "50%, 25%, 25%"
                    cols = "40%, *">
  • 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
  • Scrollbars are implicitly included if needed (they are needed if the specified document will not fit)
  • If a name attribute is included, the content of the frame can be changed later (by selection of a link in some other frame)
  • Note The Frameset standard must be specified in the DOCTYPE declaration
  • See the frame: frames.html.
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.0 Frameset//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
 
<!-- frames.html
     An example to illustrate frames
     -->
<html xmlns = "http://www.w3.org/1999/xhtml" xml:lang="en">
  <head> <title> Frames </title>
  </head>
  <frameset cols = "20%, *">
    <frame src = "contents.html" />
    <frame src = "fruits.html"  name = "descriptions" />
  </frameset>
</html>
  • The target attribute in <a> ensures that new content is displayed in the correct frame.
  • Here the contents of the first frame of frames.html, is the table of contents for the second frame: contents.html
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<!-- contents.html
     The contents of the first frame of frames.html, 
     which is the table of contents for the second frame
     -->
<html xmnls="http://www.w3.org/1999/xhtml" xml:lang="en">
<head> <title> Table of Contents Frame </title>
</head>
<body>
<h4> Fruits </h4>
<ul>
    <li> <a href = "apples.html"  target = "descriptions"> 
            apples </a> 
    </li>
    <li> <a href = "bananas.html"  target = "descriptions">
            bananas </a>
    </li>
    <li> <a href = "oranges.html"  target = "descriptions">
            oranges </a>
    </li>
</ul>
</body>
</html>
  • and fruits.html is the initial page to be displayed in the second frame.
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 
<!-- fruits.html
     The initial contents of the second frame
     of frames.html - a general description of fruit
     -->
<html xmlns = "http://www.w3.org/1999/xhtml" xml:lang="en">
  <head> <title> General Information on Fruits </title>
  </head>
  <body>
    <p>
      A fruit is the mature ovary in a flowering plant.
      Fruit is clasified by several characteristics, the
      most important being the number of ovaries included.
      If only a single ovary is included, it is called a
      simple fruit.
    </p> 
  </body>
</html>
  • For the frames example to work, you will need to download contents.html and fruits.html. The additional files apple.html, orange.html and banana.html do not exist (but you are invited to create them).

Nested Frames

  • It is possible to use nested frames to divide the screen in more interesting ways.
  • Here is an example of nested frames (nested_frames.html)
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.0 Frameset//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
 
<!-- nested_frames.html
     An example to illustrate nested frames
     -->
<html xmlns = "http://www.w3.org/1999/xhtml" xml:lang="en">
  <head> <title> Nested frames </title>
  </head>
  <frameset cols = "40%, *">
    <frameset rows = "50%, *">
      <frame src = "frame1.html" />
      <frame src = "frame2.html" />
    </frameset>
    <frameset rows = "20%, 35%, *">
      <frame src = "frame3.html" />
      <frame src = "frame4.html" />
      <frame src = "frame5.html" />
    </frameset>
  </frameset>
</html>

Exercise to Better Understand Frames

  1. Create, test and validate an XHTML document that includes two rows of frames with two frames in each row. The two left-hand frames must occupy 25 percent of the width of the display. The bottom two frames must occupy 40 percent of the height of the display.
    • The top-left frame must display the name of your mother and all of her siblings. (There must be a minimum of two siblings, make them up if you must.)
    • the bottom-left frame must display the name of your father and all of his siblings. (Once again, there must be a minimum of two siblings.)
    • Each name in the left frames must be link to a document that is displayed in the right-hand frame when the link is selected.
    • The documents in the right-hand frames are short descriptions of the people.

Syntactic Differences between HTML & XHTML

  • Case sensitivity
  • Closing tags
  • Quoted attribute values
  • Explicit attribute values
  • id and name attributes

The Structural and Presentation Layers

eg-259/xhtml.1327067870.txt.gz · Last modified: 2012/01/20 13:57 by eechris