------------------------------------------------------------------------------
MC logo
Lab 1.3b. HTML II
[^] CSc 114 Labs
------------------------------------------------------------------------------ This lab explores some ways to control the appearance of a web page. You'll start with an existing page, and modify it to change its appearance. Generally, whenever you make changes to the page using Notepad, you should refresh the browser to see the effect.

When you are done, copy your file to the server as in previous labs.

Part 1: Characters

  1. Download alice.html and store it on the desktop. You may want to right-click the link, then choose “Save Link As” or “Save Target As”.
  2. Find the file on the desktop, and double-click it to open the web browser.
  3. Open notepad from the start menu, and use it to open the file as well.
  4. Add a <head></head> containing an appropriate <title></title> element. Reload the browser.
  5. The original document uses pairs of single quotes for quote marks. For instance, part of the first paragraph looks like this:
    over its head.  ``Very uncomfortable for the Dormouse,'' thought Alice;
    ``only, as it's asleep, I suppose it doesn't mind.''
    Notice that pairs of characters are used to open and close each quotation. Your browser renders it like this:
    over its head. ``Very uncomfortable for the Dormouse,'' thought Alice; ``only, as it's asleep, I suppose it doesn't mind.''

    We can improve the appearance of quotes by using the &ldquo; and &rdquo; entities instead. The HTML will look like this:

    over its head.  &ldquo;Very uncomfortable for the Dormouse,&rdquo; thought Alice;
    &ldquo;only, as it's asleep, I suppose it doesn't mind.&rdquo;
    Which your browser renders as:
    over its head. “Very uncomfortable for the Dormouse,” thought Alice; “only, as it's asleep, I suppose it doesn't mind.”
    Use the Edit/Replace facility of notepad to replace each `` with &ldquo;, and each '' with &rdquo;:
    1. From the Edit menu, choose Replace.
    2. Enter `` as the “Find What”.
      That's two left single quote characters, not a double quote! Look in the upper left corner of the keyboard.
    3. Enter &ldquo; as the “Replace With.” Don't forget the semicolon!
    4. Click “Replace All”
    Repeat the procedure to replace '' with &rdquo;.
  6. The original document uses -- for a dash. You should replace these with a real dash. Use the Edit/Replace facility to replace each -- with &mdash;. It will look best if you put a space on each side of the &mdash;, so replace each pair of dashes with a space, &mdash; and another space.
  7. The Mad Hatter sings an unusual version of Twinkle, Twinkle, Little Star which involves bats. In the downloaded page, this section looks like this (after the quote substitutions mentioned above):
    &ldquo;We quarrelled last March &mdash; just before <i>he</i> went mad, you know &mdash; &rdquo;
    (pointing with his tea spoon at the March Hare,) &ldquo; &mdash; it was at the
    great concert given by the Queen of Hearts, and I had to sing</p>
    <p>          `Twinkle, twinkle, little bat!
                How I wonder what you're at!'</p>

    <p>You know the song, perhaps?&rdquo;</p>
    <p>&ldquo;I've heard something like it,&rdquo; said Alice.</p>
    <p>&ldquo;It goes on, you know,&rdquo; the Hatter continued, &ldquo;in this way: &mdash; </p>
    <p>          `Up above the world you fly,
                Like a tea-tray in the sky.
                        Twinkle, twinkle &mdash; ' &rdquo;</p>
    <p>Here the Dormouse shook itself, and began singing in its sleep

    In the browser, the line breaks are lost, the section looks like:
    [Song lines run together]
    The <pre> tag is used to tell the browser to keep the original spacing. Replace the <p></p> surrounding each section of the song with <pre></pre> tags, and arrange the lines so the page looks like this:
    [Lines Arranged]

  8. In the second paragraph, the word PLENTY is given in all caps. Change it to be lower case italics, like plenty. You may recall that <i></i> creates italic text.

    The next two steps are optional
    If you're running behind on time, feel free to skip these last two steps. You may return to them as you have time.
  9. Find the other words which are all caps and change them to be italics, just as PLENTY. I found 17 other cases.
  10. There are quotes within quotes which are set off with ticks, `just like this.' They would look better if they were replaced with &lsquo; and &rsquo;, respectively: ‘like this’. Make that change where needed. There are about ten places.

Style Sheets

Style sheets are a relatively new facility in HTML which allow the page creator to control the way the a browser displays features of his or her page. First off, add a style section. It should go wherever you like within the header. For now, it's empty, so the top of your page will just like like this:
<html>
<head><title>...</title>
<style>
</style>
</head>
<body>
<h1>ALICE'S ADVENTURES IN WONDERLAND</h1>
...
Between the <style></style> tags go directions to the browser about how certain tags should be displayed. This gives you a good deal of control over how the page appears.

In this portion of the lab we will add style directives, but make no other changes to the document. All the changes in this section are made between <style> and </style>.

  1. Add this line between the <style> and <\style>:
    h1 { font-size: 130%; }
    This gives an instruction about how to display the <h1> tag, and the instruction is that the size of the characters used (the font size) should be 130% of normal. That is, 30% larger than the regular text. Add this line and refresh your browser. You should actually see the title get smaller. This is because the browser normally displays <h1> text at something over 200%, so we have actually told it to make the text smaller than it usually does. Mine looks something like this:
  2. Add similar instructions to set text sizes for <h2> and <h3>. Choose descending sizes which are still larger than the normal text (more than 100%).
  3. Observe where the author's name is listed. The HTML is
    <p class="author">Lewis Carroll</p>
    The class attribute is designed to work with style settings. Add the following line to the <style></style> section:
    p.author { font-size: 125%; font-style: italic; }
    Now refresh the browser. This direction tells the browser how to display a paragraph which is marked with the class="author" attribute. (In our case, we only have one such.) The author's name is larger, and displayed in italics.
  4. Now, to each of the directions you just created, for h1, h2 and p.author, add the direction text-align: center;. For instance, your h1 instruction might become:
    h1 { font-size: 130%; text-align: center; }
    Add this direction to h2 and p.author as well. Reload the browser. Mine looks like this:

  5. A couple more changes in the titles. For each of the h1, h2 and h3 directions, add this: font-family: sans-serif;. This changes the font to something more usual for titles.
  6. Secondly, for the h1 (but not the other hn tags), add this: margin-bottom: 2pt; and for the p.author add the similar one: margin-top: 0pt; Reload the browser. The browser puts a certain amount of space before and after things. Here, we're telling it to put two points after the <h1></h1>, and zero before the author paragraph. These settings are both less than what the browser will do without instruction. A point is a printer's unit, about 1/72 of an inch. Letter sizes (font sizes) are measured in points; 12-point is a common size.

    After all these changes, the top of my page looks like this:

  7. Now add this instruction to the <style></style> section:
    p { margin-top: 2pt; margin-bottom: 0pt; text-indent: 0.25in; }
    This applies to all paragraphs, so it will have a significant effect on the appearance of the document. It sets margins, and the text-indent instruction asks for indented paragraphs rather than the block ones the browser produces by default. Reload the browser.
  8. If you look carefully, you may notice that the author's name is no longer centered properly. If you can figure out why, fix it. (If not, just proceed. We'll talk about it later.)
  9. Since the entire document is contained within the <body></body> pair, directions for its display can change the appearance of the whole document. Start by adding this directive:
    body { margin: 0.75cm; }
    Reload, and you will see some blank space around the edges of the document. The units here are centimeters.
  10. You can also control the colors in the document from the style sheet. The color: directive sets the color used to display the text, and background-color: sets the, uh, background color. Add these to our existing body directive. Choose some colors for text and background which you like, which go together, and have enough contrast that you can still read the page. (What happens if you make them the same?) For a dramatic effect, you might try a dark background with lighter lettering.

    You may specify any of the 16 named colors, or use the numeric notation, like #8844AA.

  11. Finally, the two song sections which were formatted with <pre></pre> look funny because they are set in a different font. Fix it with
    pre { font-family: serif; }
    You might also want to set a left margin to indent the songs if you think that looks better.


(Hopefully, your colors are different from this.)

Adding An Inset

This section is optional.

This section is optional, though I hope you will have time to do it. In any case, make sure to send your page to the server and use the URL submit page to record your page's url for credit.
In this section, we will add a small inset in the side of the page. Add the following between the first and second paragraphs:
<div class="rightinset">
<a href="http://en.wikipedia.org/wiki/Lewis_Carroll">Lewis Carroll</a><br>
<i>Other Works</i><br>
Through the Looking-Glass<br>
The Hunting of the Snark<br>
Phantasmagoria and Other Poems</div>
Refresh the page. A <div></div> stands for “division” and its only purpose is mark out a portion of the document to which style directions may be applied. Presently, we have given none, so the new text appears much like a paragraph, right were we put it between two others. But we have given a class attribute, so we're ready to make this more interesting.
  1. First off, we want to be an inset, so it should stay to the right and the main text should flow around it. The required style incantation is:
    div.rightinset { float: right; width: 200px; }
    The width directive simply keeps it from taking up a lot of horizontal space, and the float makes it stay at the right and the text flow around. If you like it better at the left, feel free to float it there.
  2. Put a box around it. Add the direction
    border: 1px solid black; 
    to the instructions for div.rightinset (Feel free to use several lines now that it's getting kind of long. You can start a new line anywhere spaces go.) You might want to choose a color other than black to go with your page colors.
  3. Make the font size in the inset a little smaller than the usual size.
  4. Add the text-align: center directive to the inset block.
  5. Set text and background colors for the inset. Choose colors that look nice with main body colors.
  6. You may want to add some margin to the inset to push the surrounding text away from the box. If you want to push the box away from the text it contains, that is called padding; you can specify padding: size much as you specify margins. Set what you think looks nice.
  7. To change the text in the link, use a directive like this:
    div.rightinset a {...}
    Whatever you put here will apply to any <a></a> (all one of them) within the <div> marked rightinset. You should make the text there larger, and set the color to something that goes with the rest of your page. You may want to use bold or italics if you think that looks best.
  8. Download the following picture:

    Add it your page wherever you like. Have it float to the left, so the text flows around it.
  9. While you're at it, add this one near the bottom:

    Float it however you like. Images also take the border directive if you would like to add one.


And Now

Use the FTP program to put your web page on the server. If you inserted images in the last section, send them as well.