An Algorithmic and Social Introduction to Computer Science (CSC-105 2000S)


Using and Building Styles

Goal: In this laboratory, you will investigate the effects of cascading style sheets. Along the way, you will consider when one might want to define new logical tags and eventually build your own style sheets.

Note: We've left some space after each question for you to enter your answers. You need not write down your answers except for the few questions that specifically say ``Enter your answer here''.

Basics

In the first part of this laboratory, we will consider ways to affect the appearance of a sample document which may be found on the Web at http://www.math.grin.edu/~rebelsky/Courses/CS105/2000S/Examples/syntax.html. Midway through the lab, you will need to make your own copy of the sample document.

Customizing the Browser's Font

As you may know, Netscape and other browsers allow you as reader to partially customize the appearance of other pages on the Web. First, bring up the sample document.

Next, select ``Preferences'' from the ``Edit'' menu. If you see ``Fonts'' at the left, click on it with the left mouse button. If you don't see ``Fonts'' on the left, click on the triangle to the left of ``Appearance'' and then click on ``Fonts'' when it appears. Set the variable-width font to ``Times (Adobe)'' 18 point. Click OK. What happens to the sample document?


 
 
 

Switch the font to Helvetica 12pt. What happens to the sample document?


 
 
 

Switch the font to Times 12pt (or whatever you'd prefer as a default). You've now explored the primary control

Discussion: Who Controls Document Appearance?

Once we've reached this point, we'll take a short break to discuss user control of document appearance.

Adding a Style Sheet

I've set up a number of sample style sheets for use with this document. Make your own copy of the sample document by clicking and holding on the link with the right mouse button and then selecting ``Save Link As ...''. You may also choose to load the page directly from http://www.math.grin.edu/~rebelsky/Courses/CS105/2000S/Examples/syntax.html and then use ``Save As ...'' from the ``File Menu''.

Open your copy using dtpad. Add the following lines to the head of the document (right before the tag that reads ``</HEAD>''.

<LINK REL="stylesheet" TYPE="text/css"
      HREF="http://www.math.grin.edu/~rebelsky/Styles/dobbs.plain.css">

Save the modified file and then load it using Netscape. Ask me if you don't remember how to load a local file using Netscape.

What effect does the style sheet have on the document?


 
 
 

Using the preferences window (which you learned how to access earlier), set the font to times 18pt. What effect does the font change have?


 
 
 

In the font preferences window click the button next to ``Use my default fonts''. What effect does this have? Is that what you expected?


 
 
 

Restore your settings (select your preferred font; check ``Use document's fonts'').

Considering Components

There are many parts of this long document that play many different logical roles. Identify about four different roles within the document. Record them here.


 
 
 
 
 
 

How might you choose to represent those roles visually?


 
 
 
 
 
 

Other Styles

You've selected one style sheet for this document. However, it is possible to create other style sheets. I've created a few for you to experiment with. Reopen the document with dtpad and change the style sheet to each of the following. Consider the changes that each has.

You may also want to see which styles allow you to change the font from the preferences window.

Which, if any of the styles do you prefer?


 
 
 

Discussion: Designing a Style Language

We'll take a second break to consider how we might write our own style language (and look at some details of CSS).

Your Own Styles

We probably won't get to this part.

You are now ready to build your own style file. For convenience, you'll build a style file for the ``Syntax: Models'' document. That document uses the following ``logical'' tags.

Using dtpad, create an empty file called dobbs.css. Update your HTML file to use that style file. (If you're not sure how to do this step, ask one of your classmates or SamR for help.) What happens when you reload the HTML file in Netscape?

First, we'll update all the paragraphs (or nearly all the paragraphs) to use green text. Add the following lines to dobbs.css

P {
  color: green;
}

Save the modified dobbs.css. Then force-reload the page in Navigator. (To force-reload, hold down the shift key before you click on the ``Reload'' button.) What happens? What does this suggest to you?


 
 
 

It seems that we should highlight the note at the top of the page. Add the following lines to dobbs.css.

P.annotation {
  color: red;
  background-color: white;
  margin-left: 1in;
  margin-right: 0in;
  border: solid;
  border-color: yellow;
  font-size: small;
  text-align: right;
}

What do you expect each line to have? You may want to put your notes next to each of the lines.

To confirm your answer, save the file, and then force-reload. You may also want to try variations of each of those parts.

Next, we'll center the document's top-level heading (the displayed title). Add the following lines to dobbs.css, save the file, and then force-reload.

H1 {
  font-family: Helvetica;
  text-align: center;
}

So far, we've only affected things at the block level (that is, whole paragraphs or things like paragraphs). How might we change things within paragraphs? Remember that we've been using variants of STRONG and EM.

Perhaps we want strongly emphasized text to be larger. We might write

STRONG {
  font-size: 120%;
}

Pick your own way of representing strongly emphasized text. You may wish to record the style here.


 
 
 

Divisions

What if we want to affect multiple paragraphs? For example, suppose we wanted the first section (about nouns) to have a white background. HTML supports a DIV (division) tag that does nothing but allow you to apply styles to multiple sections grouped together. We might write the following style.

DIV.nouns {
  background: white;
  border: ridge;
}

How do we then apply it to that section? We put

<DIV class="nouns">

before the section and

</DIV>

after the section.

Try adding the style and adding the two tags.

Have Fun

If you have time left, see how creative you can be with this document.


History

1 September 1999

1 February 2000


Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.

This page may be found at http://www.math.grin.edu/~rebelsky/Courses/CS105/2000S/Labs/styles.html

Source text last modified Tue Feb 1 09:35:52 2000.

This page generated on Tue Feb 1 09:34:04 2000 by Siteweaver. Validate this page's HTML.

Contact our webmaster at rebelsky@grinnell.edu