ATSC 212 - Web 2
Goals. To learn how to create web pages using:
- anchors
- colour
- cascading style sheets (CSS), both internal and external
Demonstrated in Lab Exercise 2: Edit a glossary.
Web Authoring - Part 2. In-class Demo:
Demo of Anchors, Colour, and Cascading Style Sheets (CSS).
In this demo, you will create a weather glossary, as a way to
demonstrate anchors, colour, and CSS. Do all the following inside KompoZer.
Create directories and import files, to use later in class:
- Open you Z-drive, and navigate to your Website folder. Open that folder.
- Inside the Website folder, create the following New Folders
- glossary
- Close your Z-drive window.
- Using your web browser (e.g., Mozilla), navigate to the course web page
http://www.eos.ubc.ca/courses/atsc212/ - Click on the Labs link, and then click on the link for week 3 Web-Authoring-2.
- On that web page, in the section called "Files to be Used in Lab Demo"
- Right click on the "storm glossary A-B" link, and copy the html file into your "glossary" folder
- Right click on the "storm glossary C-D" link, and copy the html file into your "glossary" folder
- Minimize or close your web browser.
- Run (double click) the KompoZer program.
- In
the KompoZer Site Manager pane at left, to the right of the "Edit
sites" button, click on the "refresh" button (the yellow curved arrow).
- Expand
the file listing under your Website, in that Site Manager pane, to see
all your files. You should see the new folders, and the new files
you put in those folders.
Demo of Anchors:
- In the KompoZer Site Manager, double click the "stormglossaryab.html" to
open it in the editing window. This has some glossary terms
already typed in, to make your life easier.
- Click once just to the left of the line "-A-", to put the insertion point at the start of that line.
- Click on the "Anchor" button, to insert an anchor there, and name it "A".
- Create another anchor, named "B", at the start of the line "-B-".
- We will now add a navigation line, to make it easier for the
reader to jump to any letter in the alphabet. We will add the following
into new lines just before the line that says "-A-".
- Insert a horizontal line (use the "Insert" menu at the top of
the window, or the "horizontal line" tool if you had added it to your
customized toolbar from last week).
- Immediately after this horizontal line, insert this text "[ A , B , C, ... ]".
- Center this text in the page, using the center align button in the tool bar.
- Add another horizontal line after this centered text
- In the line where you already have "[ A , B , C, ... ]", use the mouse to select the letter "A".
- Hit the "Link" button, and in the white space where it asks you
to insert the Link location, use the mouse to select the down-pointing
triangle to display a pop-up-menu of anchors.
- Click on the A anchor "#A", and then hit the OK button.
- Similarly, for the letter "B" in the list "[ A , B , C, ... ]", create a link to the "#B" anchor.
- With the mouse, select the 3 lines that hold the 2 horizontal
bars and the "[ A , B , C, ... ]", and copy them (via the Edit menu, or
via a right-click on your mouse).
- Paste these 3 lines at the very bottom of the page. Now,
for the convenience of the reader, we have navigation lines near both
the top and bottom of the glossary.
- After the last horizontal line, type your copyright line
"Copyright © 20xx by YourName", and then from the "body text"
pull-down menu, select "address", and then reduce the font size.
- Save.
- Hit the Browse button, to see if the links to your anchors work as expected. Always check your work.
- Close or minize your browser, so you can do more work on KompoZer. Keep the glossary page open in your edit window.
Demo of Internal Style Sheets, and of color:
First, you will create an internal style sheet within your glossary web page.
- Continue editing your glossary web page.
- From
the composition toolbar near the top of the KompoZer page, select the
icon labeled "CaScadeS", which looks like a painter's palette. Or
from the "Tools" menu at the top of the screen, select "CSS Editor".
- (If it askes if you want beginner or expert mode, select "Expert Mode" if it is not already checked.)
- In the pop-up CSS window that appears,
- Select the radio button "style applied to elements of type"
- At
the right of the white space beneath the 4 buttons, click the
triangular button to get a pull-down menu, and select "h2 (Heading 2)".
This
tells the editor that whenever it encounteres a header-2 in your web
page, it will format it in the way that you are about to specify.
- Click on the button "Create Style Rule". Then, with that
"h2" rule highlighted in the left "Sheets and Rules" pane, click
on the "text" tab above the right pane.
- In the text-edit box that appears, click on the button to the
right of the "color" space, and pick a dark red color from the color palette and click "OK".
- Create
another Rule as follows. In the "Sheets and Rules" pane at left,
click once on the "internal stylesheet" to select it. Then, just
above, next to the CSS painters palette icon, click on the triangle to
show a pull-down menu. Select "Style Rule" to create a new rule.
Then, follow steps 4a-4d above, except select paragraphs "p"
from the pull-down menu, and make them be italic.
- Create a 3rd Rule (starting similar to set 5 above), except.
- But this time select radio button "style applied to all elements of class"
- In
the white text-entry space, you will see a "period" already typed for
you at the beginning. It is important to keep this period as the
first character in the style name. Immediately after that period,
type in the name "term", and hit the "Create Style Rule" button.
- Back under the "text" tab, make it: bold, larger size, and dark green.
- Create a 4th rule. Again a "style applied to all elements of class", but name it "keyword". Make it bold, and make the font style be "normal".
- At this point, the left pane in the CSS editor should say
"internal stylesheet", and should list under it your 4 rules: "h2",
"p", ".term" , ".keyword" . In web pages, named styles are known
as "classes".
- Click "OK" to close the CSS Editor.
- Back in your glossary web page, select the "source" tab at the
bottom of the window. Scroll to the top of that page.
There, near the top, you should see all the style definitions
listed for "h2", "p", ".term" , ".keyword". Because these style
definitions appear inside the web page where you use them, it is known
as an "internal style sheet".
- Select the "Normal" tab at the bottom of the window, to go back into normal editing mode.
- Save.
Next, you will use these styles in your glossary web page:
- Click anywhere in the first glossary definition to leave the
insertion point there. Then go to the "body text" pull-down menu to
select "paragraph". See how that paragraph is automatically
formatted according to your own paragraph style (namely, italic).
- Do this same procedure for the next few definitions.
- Next, click once in the line that says "-A-", and choose "Heading
2" from the "Body Text" pull-down menu. See how default aspects
of Heading 2 are applied (i.e., larger size), with the addition of your
own style attribute (dark red) from your internal style sheet.
- Similarly, change "-B-" to Header 2.
- Back in the first glossary item, use your mouse to select the
term "AC". Then, from the "class" pull-down menu (near the "body
text" pull-down), select your style rule "term". You should see
that the word "AC" becomes bold, larger size, and dark green.
However, note that it is still italics even though you didn't
define your "term" rule to be italic. The reason is that this
term is imbedded inside your paragraph of the whole definition, and the
italic attribute from the paragraph cascades down to also apply to
everything inside the paragraph.
- For the next few glossary items (ACCAS, Accessory Cloud, etc.), also
select them with your mouse, and choose the "term" style class.
They should also become bold, larger, and green.
- Next, under the ACCUS definition, double click on the word
"instability". This is a key word, so from the class pull-down
menu, select the style "keyword". It should become bold, and NOT
italic. Why did this become not-italic, even though it is
imbedded in the paragraph. The reason is that we specifically set
this font style to be "normal", not to be "unspecified".
Therefore, the "normal" un-italicized style overrode the paragraph
style. Again, a good example of how styles cascade from a series
of rules.
- Find another key word, such as "wind" in the Advection definition. Change its class style to "keyword".
- To see how all this works as html, select the "source" tab at the
bottom of the window. It still has your internal style
definitions near the top of the page. Further down the page, see
what it did to apply your new named style classes to your terms and
your keywords. It used the "span, /span" tags to span a
range of words, and then applied your named style to that span.
- Using the tab at the bottom of the window, go back to Normal view.
- Save.
Next, you will change your existing style from an internal style to an external style sheet.
- In KompoZer select the CSS editor (either from the
CaScadeS icon in the composition toolbar, or from the "Tools"
menu at the top of the window, select "CSS Editor".
- In the left pane of this editor, if the "internal stylesheet" is
not already highlighted, select it by clicking once with your mouse.
- Then, in the under the General tab, click on the button "Export stylesheet and switch to exported style"
- A small window will appear, where you can enter the name for this
exported style. Call it "glossary-style.css". Make sure to
have the suffix ".css", which denotes Cascading Style Sheet. Navigate to your "glossary" folder before you hit
the "Save" button in this little window, in order to save this Cascading Style Sheet in your glossary folder.
- Hit "OK" to close the CSS Editor.
- You should see that you glossary web page looks the same, with
the red alphabet letters, the green terms, and the bold keywords.
- But if you click the "Source" tab at the bottom of the window,
you will find that your style definitions no longer appear at the top
of your glossary page. Instead, there is a reference to the
external style sheet that you just created. The reference is
something like: '<link
rel="stylesheet" href="glossary-style.css"
type="text/css">'.
- If
the CSS editor accidently gives an absolute reference that looks
something like: href="file:///.../glossary-style.css", be aware
that this won't work if we
upload the file to a server. Instead, we must edit the raw html
code within this Source view to convert it into a relative file reference:
- Near the top of your Source page, in the portion of the style link where it says
href="file:///.../gloss-style.css", you need to select and delete all
the words starting with "file" and including the last "/".
- After
this change, the resulting edited text should say
href="gloss-style.css", where you must keep the quotation marks
as shown at left.
- Copy that whole style link (via right click) for later pasting. For the example here, I would copy
'<link rel="stylesheet" href="glossary-style.css" type="text/css">'
- At the bottom of the window, click the "Normal" tab.
Hopefully your glossary is still formatted correctly, and now
will upload properly to a server.
- Save.
- Close the stormglossaryab window.
Now, to show the power of external style sheets, you will link the CSS sheet you just created to another file.
- In the KompoZer Site Manager, double click the "stormglossarycd.html" to
open it in the editing window. This has the C to D glossary terms
already typed in, to make your life easier.
- Open the CSS editor (CaScadeS).
- In
the pop-up editing window, use the small triangle next to the CSS
painters palette to pull down a list of options, and select "Linked
Stylesheet".
- Click the "choose file" button to navigate to your "glossary-style.css" file.
- Then click "open", and then click "Create Stylesheet". Finally click OK and close the CSS editor.
- Click
the "Source" tab at the bottom of the window, to view the raw html
code. You should see your style sheet referenced in the header of
your document.
- Click the "Normal" tab at the bottom of the window.
- Save.
- As you did for the A-B glossary, click in any glossary line and
select "paragraph" from the "Body Text" drop-down menu. The
paragraph should automatically appear in italics, as you had set in
your style sheet. Do this for some of the other definitions too.
- As you did for the A-B glossary, click in the line that says "-C-", and
select "Heading 2" from the "Body Text" drop-down menu. The heading should be automatically colored red. Do this
for "-D-" too.
- As you did for the A-B glossary, click in the first term of each
glossary definition, and select style class "term" from the drop-down
menu (just below the Body Text drop down menu). Do this for some
of the other definitions too.
- As you did for the A-B glossary, double click on any key word in a
glossary definition, and select style class "keyword" from the drop-down
menu (just below the Body Text drop down menu). Do this for some other key words that you find too.
- Save.
- To
see the power of using style sheets, lets modify the style slightly.
Go to the CSS editor, where your "glossary-style.css" should
appear. Beneath that file name, click on one of your style rules,
such as "keyword". Then, in the "text" tab, change its colour to purple.
Click OK & OK. You should see all the keywords in your
stormglossarycd change to purple automatically. And similar
changes are happening automatically to your stormglossaryab file.
Save it.
- Close the stormglossarycd window.
- The
in-class lab demo is finished. You may quit KompoZer, back up
your work onto your memory stick, and log out of your computer.
The net result is that once you have created a style sheet, you can use
it to stylize many other pages. More importantly, if you decide
to change your style later, you need change only the one style sheet,
and all the other pages based on this style sheet will automatically
change. This is a great time saver, because we humans frequently
change our minds about how we want thinks to look.
-end-
Copyright © 2010 by Roland Stull
University of British Columbia
.