Allen & Company HTML for Newcomers
Home Index IntroductionLesson 2


Using this Lesson

 
If you've completed the Introduction you know how to use this Lesson. If not, remember:

Adding style with CSS

In Lesson 1, you marked up the plain text notes (from the Introduction). In this Lesson, we'll use the file you created, and add some rules to it. It's better to use your own file, but if you don't have it, download this exampleactive.htm file now.
In , we'll add a little style to active.htm with rules. If you're unsure of what means, hover your mouse over for a brief description.

Remember that you can (for details, click here).

Open active.htm in Notepad

If you have Notepad's window open from the previous Lesson, you can skip .

Notepad will not be the application registered to open HTM files (this will be your default browser's job), and so we'll need to use Notepad :

Remember: you can hover your mouse over a term in purple text to read more details about it. Both and purple text are InfoBox cues. We use a distinctive, bold purple cue where it's more appropriate. Either way, you'll know there are more details you can read whenever you want, simply by hovering your mouse over this device.HTML=HyperText Markup Language is a system of tags to specify text layout. A tag looks like <b>M</b>, which says: put the letter M in bold. A <b> says start making what follows bold, and a </b> says stop. Tags usually come in start/stop pairs. It's how we put bold letters in "HyperText Markup Language". A browser (such as Internet Explorer or Mozilla) doesn't show the tags, it obeys them. An editor like Notepad merely shows the tags along with other text. Cascading Style Sheets are a system of rules to add style. HTML includes tags for basic style features, but it was never meant to handle fine details. So CSS was added. CSS codes supersede old HTML tags. "Style Sheet" is an old name for a Print firm's style manual. And "Cascading" because you can add new rules over old ones. Together, the rules apply in an order called the Cascade. In some Windows versions (eg Windows Millennium), the Open With option is shown at the first Right-click, so you won't need to use the  Shift +Right-click method that we explain in .

 Note  Remember to use the Notepad window in its default size.

Restored means a window that's neither maximized nor minimized. Its control buttons look like this . Using Notepad in a restored window means you can see the CueWindow properly. When several windows are open, only one has focus (it has a standard dark blue title bar). The window with focus is the one that receives any keystrokes from your keyboard. Where a window has keyboard input boxes, the box with focus is the one that typed characters will appear in. An easy way to shift focus is to click on a window (or its Taskbar button), or click in an input box. You can also use  Alt Tab  to put up a menu that will cycle the focus through all windows.

View as HTML

If your  HTML view  window is still open from Lesson 1, skip this re-opening step. If not, the below will help you open your active.htm document in a Browser window scaled to fit the Lesson's window layout, as before.

Click in the box, enter filename – or browse

Enter full path, or click Browse and locate your file:



Either enter the to the active.htm file in the box; Or use the  Browse  button to find it; then click on it; then click the  Open  button (you can use the Files of type pull-down box to look only for *.htm,*.html files to make it easier to locate).

The full path to a file includes its drive letter and folder name(s), too. For a file on your Desktop this might look like: c:\windows\desktop\active.htm but it will vary with your Windows version and setup. Notice that you need to click in the box first (to set focus) before you can type in it. If you prefer, use the  Browse  button to find active.htm with an Explorer control.

Document as HTML

With the path to your file in the box, click the  View as HTML  button. A new window opens, placed so you can compare your progress at each  Step  with a .

The Lesson plan:
Using CSS rules

 
Lesson 1 dealt with basic , now let's add some Style with . We'll split the job into four logical stages, and learn some useful rules. This is the plan:

Cascading Style Sheets:
  1. Changing Body font and colour
  2. Making Spans of inline text stand out
  3. Defining Blocks of text and Classes
  4. And finally, a Flashy finish

With rules, you can easily change fonts and colours. You can even create rules to change (or add to) the rendering of standard tags, as we'll soon see,

CSS rules can be kept in a separate file

A useful way to work with rules is to keep them in a separate file, which all your pages can use. That means you can change a style feature throughout an entire website by changing its rule in only one file. For our present purpose, however, we'll put our rules in the , where they apply to the whole of the current document.

Body settings:
Font and colour

 
Changing overall settings for the document:

  1. Changing Body font and colour
    • changing the body settings
    • the font-family rule
    • the font-size rule
    • the background-color rule
    • the (text) color rule

The tag

In the of our document, we can specify rules enclosed between and </> tags. These rules will apply to the whole document :

Remember to get help

Use the help built into this page (it's there whether you stay online or ):

 Note  There's no need to learn these details as soon as you meet a new term. Let the Lesson guide you through the initial steps. Then only when you need to remind yourself, or want to learn more – the boxes show additional syntax examples not covered in the main Lesson.

Rules for the

We used the standard tag to mark our document's main content. We can alter the meaning of this tag with a rule. For example, we can add a rule about what font to use, and it will apply to all text between and .

To change any tag's meaning, this is what we need to do:

Specifying

We can choose which font the will use with the rule. We'll use Arial. It's a standard, Microsoft font found on most machines :

A serif is a decoration at the end of a letter stroke. A sans-serif font is a font designed without any serifs. This shows a capital "H" in a sans-serif  and a serifed font together. Arial is a Microsoft font very similar to the standard sans-serif font Helvetica. The document Body is where the main content of the page goes. In simple pages, it may be just paragraphs of text. In more complex cases there will be text, images, tables, and a variety of other content. The Body is contained between <body> and </body> tags. The Head is where the properties of a document, such as Title, Keywords (for search engines), Style details, Script functions, and many other administrative elements go. Most of these are not seen by the user. The Head is contained between <head> and </head> tags.

Any problems?

Browsers are very strict on spelling and punctuation in rules. They will ignore any rules that are misspelt or mispunctuated, and may even ignore (correct) rules that follow them. So, if the  HTML view  of your document doesn't respond to any rules you add, check all the spelling of tags and rules carefully.

And remember: you must save Notepad changes before  HTML view  will show them.

Specifying

We can add a rule to change the font's :

In CSS rules, the em-height is the full height of a font from the  top of an ascender to the  bottom of a descender. The em-height works relative to the font size in use, so 1.5em means use 1½ times the current height. It's best not to set an absolute size (in points=1/72 inch), since some people might have set their browser to use bigger text. If we use em-height, it's relative to whatever base size they've set. In older usage, an em was the width of the font's letter  m .

And now for COLOUR ...

You specify colours with in one of five ways (we'll use the first):

  1. Any of 140 standard Colour Names in the scrollable list
     
  2. RGB hexadecimal codes: :#RRGGBB
     
  3. RGB short hexadecimal codes: :#RGB
     
  4. RGB decimal codes: :rgb(red,green,blue)
     
  5. RGB percentages: :rgb(red%,green%,blue%)

Browsers support the 16 Colour Names in the Windows VGA palette: aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red,  silver , teal, white, yellow plus 124 other Names. To see alternative RGB decimal codes for any of the 140 colours in the scrollable list, hover your mouse over one of the coloured blocks. Some are equivalents: aqua, cyan. You must spell the names exactly as shown. Some names are strangely whimsical:  oldlace, moccasin, peachpuff, plum. These specify amounts of red, green, and blue in hexadecimal from 00FF for each #RRGGBB component, eg: #000000, #8080FF, #80FF80, #FF8080, #FFFF00, #FFFFFF. For this, you need to understand additive colour mixing, for example: red+green=yellow. These are abbreviated red, green, and blue values in hexadecimal. Each hex digit is simply doubled, thus the code #A10 is treated as the colour #AA1100. These specify amounts of red, green, and blue in decimal from 0255 for each colour component, eg: rgb(0,0,0), or rgb(128,128,255), or rgb(255,255,0), or rgb(255,255,255). Again, you need to understand additive colour mixing, as in: red+green=yellow. These specify amounts of red, green, and blue in percentages from 0%100% for each component colour, eg: rgb(0%,0%,0%), rgb(100%,100%,0%), or rgb(100%,100%,100%). Again, you need to understand additive colour mixing, as in: red+green=yellow.

Remember to get help

Use the help built into this page (it's there whether you stay online or ):

 Note  There's no need to learn these details as soon as you meet a new term. Let the Lesson guide you through the initial steps.

For this Lesson, we'll use the colour names

For precise work, you'll probably use one of the numerical mixing methods, but for quickly testing a few ideas, the (faintly whimsical) Colour Names are quite useful.

We can specify the text colour with the rule, and the document's background colour with the rule.

Try :yellow;:chocolate. See what you think :


A matter of taste

Colours are a matter of taste. The 140 Colour Names make an easy way to test colour combinations. Click the  Colours  button on the right; it will re-display the list in a small window that you can drag around, and see with your Notepad window open.

You may want to play with research a few changes of and by trying some other combinations now. Remember to click File, Save after each change in Notepad, then press  F5  in the  HTML view  window to see the effect.

We'll wait here until you've finished researching ...

Spans of inline text:
Using Text-Level tags

 
Next, we'll look at how to change the appearance of individual letters, words, or phrases. This is called "Text-Level" tagging.

  1. Making Spans of inline text stand out
    • the <b> tag for emboldening text
    • the user-definable <span> tag

Emboldening text

The tag can be used to make a span of text look bold. Try using it to make the technical term: stand out :

onMouseOver is the technical term for the JavaScript event that occurs when you hover the mouse cursor over an area of screen. JavaScript is an event-driven language and its functions are often fired by such events.

The user-definable Text-Level tag:

Here, emboldening isn't very effective. We could use a rule to add a colour change to the tag. But there's a more versatile way. We'll try it with another term.

We can tag ing with the user-definable tag, . It won't appear to have any effect until we define some rules for it :

onClick is the term for the JavaScript event that occurs when you click the mouse cursor on an area of screen. JavaScript is an event-driven language. Its functions are often fired by events.

Adding rules to

We can now add rules to the tag. Let's add a colour rule :

 Note  If a rule used inside a tag needs  Space s use quotes around the rule, eg:

<span style="font-family:Times New Roman"> The Times </span>


More research ...

You may want to try some other colour combinations. Use the button to see the Colour Names list again (in a small window). Remember to save any changes in Notepad before refreshing the  HTML view  window. Remember, too, that you can read the RGB decimal values of any colour in the list by hovering your mouse over its colour block.


Adding further rules

We can make our ing appear in bold as well. We could do it with :

<span style=color:lime><b>onClick</b></span>ing or

<b><span style=color:lime>onClick</span></b>ing

Either would work. Notice that you must nest tags properly, enclosing both open and close of the inner tag within the outer. So, for example, this version would be wrong:

<b><span style=color:lime>onClick</b></span>ing because the tag opens before the tag, so the should close after the does.

The rule

However, we won't use , instead we'll use a new rule: . Add the rule to the rule :

Text in a Block:
Block-Level tagging and re-usable es

 
Now we'll turn our attention to text in Blocks:

  1. Defining Blocks of text and Classes
    • the user-definable <div> tag for Blocks of text
    • grouping rules in re-usable Classes

A Block means any chunk of content that you want to stand alone. It could be:

So, for example, this isn't a Block of text (because it's merely part of this line), whereas:

this is one,
and this is another.

But this quote: "Then felt I like some watcher of the skies when a new planet swims into his ken; or like stout Cortez when with eagle eyes he stared at the Pacific – and with all his men looked at each other with a wild surmise – silent, upon a peak in Darien" is not a Block (although it's quite long), since it's only a part of this sentence. However, this entire paragraph (Keats and all) is a Block.

Quoted from Keats: "On First Looking into Chapman's Homer". In fact, Balboa (companion of Cortés), not Cortés, was the first European to see the Pacific. Nor, understandably, was he silent, but cried out: Hombre! (Man! – Look at that).

The user-definable Block-Level tag:

We've used three Block-Level tags: , and . Each has a special function, but we could use rules to give them a quite different function, if we chose.

However, also has a user-definable Block-Level tag: (the Block equivalent of ). If we need a special block layout, it's often better to create a that meets our requirements, rather than alter one of the standard Block-Level tags.

Let's try out this idea by placing the heading of our notes in a user-definable tag instead of the tag we're using at the moment :

Using rules in a

We could add a centre rule inside the new tag. We could, but we won't. Instead we'll define a for our tag to use. A is a set of one or more rules, and we define it in the section of the document .

We must choose a name for our – we'll call it myclass. Not very informative, but amidst all the other syntax, myclass will remind us that it's a word we chose. For now, we'll just put a rule in the new :

Specify in

We need to tell the Browser to use myclass for our . The instruction for this goes inside the tag :

Re-using myclass

The purpose of creating a of rules is to re-use it elsewhere in the document. Let's put the footnote in a myclass , too :

Copyright symbol ©

While we're working on the footnote, let's add a pair of © symbols to it. We can do that with the &; symbol :

Adding rules to myclass

Now we have two Blocks (heading and footnote) assigned to myclass. If we add rules to myclass, then all Blocks assigned to it will change simultaneously.

Remember that rules can be loaded from a file. Re-usable es mean that you could re-style an entire Website with one rule change in one file.

Let's change the text of myclass and embolden it, too :


More research ...

If you're not keen on  oldlace  you may want to research other colours.


 Oldlace  acquired a comic-sinister ring from its use in the Joseph Kesselring play: "Arsenic and Old Lace" (1941). Later (1944), a Warner Brothers film, with Cary Grant as Mortimer Brewster, a drama critic with a family history of insanity, whose aunts poison lonely old men and bury their corpses in the cellar.

And finally...
Customising text

 
On a slightly less serious note:

  1. And finally, a Flashy finish
    • a <div> that's "all my own work"

Signing off

Let's sign off with a custom at the end of our document :

Centre and change font

We'll add rules on and to our new :

Add real style

We can add more rules. We could add them in same style= section. However, some Browsers (such as Internet Explorer) can handle separate style= sections on new lines, which keeps the document tidier and the lines shorter.

 Note  If you're not using Internet Explorer, keep all these extra rules inside the "quotes" of our first style= section and all on one long line – or they'll be ignored.

We'll use a rule that we haven't met before: . Make sure you keep all the rules inside the opening tag :


It's up to you ...

Of course, the precise colours for your "own work" are still up to you ...


pull-down box

Take the time to glance through the s for the tags and rules we've met. The Course Reference pull-down box grows automatically with each Lesson, so it now includes all the terms from Lessons 1 and 2, and has extra cross-references.

And finally ...

That ends this short Course in and . Try the to finish off.

We use a QuizBox not only to ask a few questions, but (in the answers) to add new details, and to explain some old points in a different way (which can help clarify difficult material). Five to ten questions is about the right number. A QuizBox isn't a test, it's a memory aid.

The Lesson summary

Remember: PreviewDoReview. We'll end with a Review of what we've learnt:

That's all for now

This short demonstration Course in HTML for Newcomers is offered as practical example of our interactive writing techniques. We hope you found it interesting and informative. You can read more about our work and the services we offer.

William Allen and Linda Allen
© Copyright 2003- Allen & Company. All rights reserved ©