Today you will get practice specifying the style of HTML tags using Cascading
Style Sheets (CSS).
In particular, we will use an existing external CSS in our document,and
then we will modify it to better fit our needs.
We may also get some practice with document-level and in-line CSS as time permits.
The Cascading Style Sheets lecture notes give an overview of CSS.
The CSS reference page describes details of the syntax, and is a useful guide to the CSS language.
Create a Lab3 folder on your desktop. You will save every document
related to this lab inside folder Lab3.
Save a copy of this document, in the folder Lab3, to
use it as a starting point. Name this copy lab3.html. (In your
browser, File --> Save
As...) View lab3.html in a browser. Notice that lab3.html does
not use any CSS at this point.
lab3.html in TextWrangler,
and add the following line in the HEAD section of the document:
<LINK TYPE="text/css" REL="stylesheet"
HREF="http://cs.wellesley.edu/~cs110/cs110-main-style.css">
lab3.html, and view it in a browser. Does it look different
now? Why? Have you seen this style of pages before? You just experienced one of the advantages of using an external style sheet: you can easily re-use existing CSS code (if, of course, it fits your purpose).
Here is how my lab3.html looks like at this point.
Lab3 folder,
on your Desktop, as my_style.css. (In your browser, File --> Save As...)lab3.html, so that it points to the new style sheet, my_style.css,
instead of the cs110
main style sheet. To do so, modify the HREF attribute, in the LINK tag in
the HEAD of the document, to look like this:
<LINK TYPE="text/css" REL="stylesheet" HREF="my_style.css">
my_style.css in TextWrangler, so you can edit
it, as follows:
BODY {background-color: green; }
BODY {color: white; }
H1 {text-align: center;}
EM {color: red;}
STRONG {color: purple; font-size: 16pt;}
img.right {float: right;
margin: 0px 10px 20px 30px;}
Here is how my lab3.html looks at this point, and this is the document my_style.css.
If you want to specify the appearance of a certain page only, as opposed to a whole web site, you can use Document-level Style Sheets . For example, we may want to change the behavior of the <P> so that, in a certain page, text between the <P> and </P> shows with a margin around and on an orange background.
To do that, add this piece of CSS code in the HEAD part of your lab3.html document:
<STYLE TYPE="text/css">
P {margin: 1cm 4cm 1cm 4cm; background-color: orange;}
</STYLE>
Save your document,
and view it on a browser to see the results. Notice how this piece of document-level
css code affects all the <P> tags in your lab3.html document.
div.ImgCaption {
width: 300;
padding: 15px;
border: 1px solid black;
text-align: center;
font-size: small;
}
Here is how my lab3.html looks at this point.
With in-line cascading sheets you can modify the appearance of a specific tag within a certain document. As an example, let's modify the <BLOCKQUOTE> so that text between the <BLOCKQUOTE> and </BLOCKQUOTE> appears with a certain-look border, and some padding around it. To do that, add the STYLE attribute to the tag, as shown below:
<BLOCKQUOTE STYLE="border: medium double black;
padding-left: 15px;
padding-right: 15px;
padding-top: 15px;
padding-bottom: 15px;">
Often times you want to center an image on the page. You can do it using in-line style sheet code to surround the image with a centered paragraph:
<P STYLE="text-align: center">
<IMG SRC="weasel.jpg" ALT="weasel image" >
</P>
Here is how my lab3.html looks at this point.
Keep in mind that using CSS this way (in-line), although convenient at times, can result in pages that are difficult to maintain and update.
Computer Science 110
Date Created: January 2006
Date Modified: February 2008