Requirements | 1. Viewing and Applying Styles | 2. Creating Styles | 3. Text Formatting | 4. Positioning
Show instructions for: FrontPage | Dreamweaver | Both
Software Requirements and Prerequisite Knowledge
- Internet Explorer and either Firefox or Netscape (to browse the Web and test pages)
- FrontPage 2003 or Dreamweaver MX 2004 (to author Web pages)
- Basic knowledge of HTML code (commonly used tags and attributes)
- About 30 to 60 minutes per session. Each session builds on the previous session.
- See the CSS links page for more information and online references.
Session 1: Viewing and Applying Existing Styles
- View the results of disabling a stylesheet.
- Go to the CSU Libraries
home page.
- Click the Disable Stylesheet link.
- Click the Enable Stylesheet link.
- Open Firefox.
- Click , , . The current page will lose its formatting.
- Click , , to return to regular browsing.
- View some other pages without their stylesheets, such as:
- Open Internet Explorer.
- Click , , . Check the three Ingore check boxes. Click . The current page will lose its colors, font sizes and font styles, but some styles will remain.
- View some of the above pages.
- Click , , . Uncheck the three Ingore check boxes. Click to return to regular browsing.
- Go to the CSU Libraries
home page.
- View the results of alternate stylesheets.
- Go to W3Schools: CSS in action.
- Click the 6 links in the "Click on the styles" section (With Style1-5 and Without styles).
- Go to ATRC: CSS Style Sampler.
- Click each of the buttons to see different stylesheets applied to the same HTML page.
- View the results of a print stylesheet.
- Go to Garst Wildlife Photographic Collection.
- Click , . Notice that the navigation is hidden.
- View the source code of an HTML page.
- Go to W3Schools: CSS in action or ATRC: CSS Style Sampler.
- Right-click in the page body. Click . (In Firefox, click , .)
- View the source code of an external stylesheet.
- Go to W3Schools: CSS in action.
- Click the 5 links in the "View the stylesheets" section.
- Can you explain what each line in each stylesheet does?
- Copy an example to your
computer. It includes an HTML page, an external stylesheet, and 3 images.
- View the example HTML page in a browser.
Click , . Create
a folder to save the file, or click . Type
example.html
. Click . - View the example stylesheet in a browser.
Click , . Type
example.css
. Click . - Right-click these links to the CSU libraries logo, the CSU logo and the background. Click or . Save all documents into the same folder.
- Open your copy of
example.html
using FrontPage or Dreamweaver. - Switch to XHTML,
with a few
div
tags andid
attributes.
or
view to see the source code. It is just plain
- View the example HTML page in a browser.
Click , . Create
a folder to save the file, or click . Type
- Link to an external
stylesheet.
- In FrontPage, click
example.css
. Click twice.
, . Click . Click - In Dreamweaver, click
Or: Click the panel on the right, click the tab, and click the Attach Style Sheet icon .
, , . Click . - Click
example.css
. Click . Click . - Switch to view. You should see that your document has been reformatted using the stylesheet.
- Switch to
<link href="example.css" rel="stylesheet" type="text/css" />
or
view. You should see that a line of code has been added that looks something like
this: - Make sure that the path to
example.css
is relative. There should be no folders beforeexample.css
. - Press Ctrl-S to save your changes
to
example.html
. - Press F12 to test in a browser if desired.
- In FrontPage, click
- Apply an existing class
to an HTML tag.
- Select the Section 1 heading. Select
- In FrontPage, for internal styles, click , , select from the List: menu, select from the Styles: menu, and click .
- In Dreamweaver, right-click the
<h1>
tag in the bar between the document and the Properties window, move to , and select .
from
the Style menu. You should see that the heading has become red.
- Repeat for the Section 2 heading. Note that you can apply a class to more than one element.
- Repeat for the Example HTML Page heading. Note that you can apply a class to different types of elements.
- Select the Section 1 heading. Select
- Apply an existing ID to an HTML
tag.
- Select the Introduction heading. Switch to
<h2>
to<h2 id="redborder">
.- In FrontPage, for internal styles, click , , select from the List: menu, select from the Styles: menu, and click .
- In Dreamweaver, right-click the h2 tag, move to , and select .
or view. Change - Switch to red border. or view. You should see that the heading has a
- Select the Introduction heading. Switch to
- Remove a class or ID from an HTML tag.
- Select the Section 1 heading.
- In FrontPage, select from the Style menu.
- In Dreamweaver, select from the Style menu.
- Repeat for the Section 2 heading and Example HTML Page heading.
- Select the Introduction heading. Switch to
<h2 id="redborder">
to<h2>
.
or view. Change - Switch to or view. You should see that the headings have returned to normal.
- Select the Section 1 heading.
- Work with styles in Microsoft Word.
- Open csspractice.doc.
- Format the first line as Heading 1.
- Format the second line as Heading 2.
- Format the remaining headings as Heading 3.
- Add some text after "Session 1: Viewing and Applying Existing Styles".
- Select "Session 1: Viewing and Applying Existing Styles".
- Click , .
- Right-click Heading 3 in the Styles and Formatting window on the right. Click .
- Change the font color to red by clicking the A with a red underline.
- Click . Notice that all styles formatted with Heading 3 become red.
- Press Ctrl+A to select all. Press Ctrl+C to copy .
- Create a new HTML document in FrontPage or Dreamweaver (press Ctrl+N).
- Paste into the new document (press Ctrl+V).
- Switch to or view. Notice that the Word headings have become h1, h2 and h3 in HTML.
- Also notice that FrontPage adds a MsoNormal class and other styles which you would probably want to remove.
Session 2: Creating Styles
- If you are not continuing from Session 1, download the example files and link the stylesheet to the Web page.
- Create an inline style to format a single instance of a tag.
- Open your copy of
example.html
using FrontPage or Dreamweaver. - Click in the upper left cell of the table in Section 2.
- Switch to or view.
- Change
<table>
to<table style="border: 5px solid blue;">
- Switch to or view. You should see that the table now has a thick blue border.
- Tip: You can use the Quick Tag Editor to make a change to a tag
without switching views.
- Select part of the page such as a table.
- FrontPage
- Click Ctrl+/, and click on a tag. , or press
- Click Ctrl+Q. , or press
- Click , and make sure is checked.
- Right-click the
<table>
tag in the Quick Tag Selector bar and click .
- Dreamweaver
- Right-click the
<table>
tag in the bar between the document and the properties window. - Click Ctrl+T. , or click , , or press
- Right-click the
- Make changes to the tag and press Enter.
- Open your copy of
- Create an internal stylesheet and format one or more existing tags
within the document.
- FrontPage
- Click
h2
tag. Click
, Click
the - Click , Select a font, size, style, color, effects, and/or character spacing. Click 3 times.
- Click
- Dreamweaver
- Click
Or click the panel on the right, click the tab, and click the New CSS Style icon .
, ,
- For the Selector Type, click the Tag radio button. Select the
h2
tag from the tag menu. - Select the radio button Define in: This document only. Click .
- Select properties such as font and/or size. Click .
- Click
- You should see that all
h2
tags in the document are now formatted differently. - Switch to
<head>
section, within a<style>
tag.
or
view. Find the CSS code that was inserted for you, in the
- FrontPage
- Create an external
stylesheet from a template.
- FrontPage
- Click
Or click the arrow next to the white New icon in the upper left corner and click
, , - Click the tab. Select a stylesheet. Click .
- Click
- Dreamweaver
- Click Ctrl-N. In the General tab, click . , or press
- Select a stylesheet in the right side of the dialog box. Click .
- Click
styles1.css
. Click .
, . Type
- FrontPage
- Create an external stylesheet
from scratch.
- FrontPage
- Click , , .
- Click the tab. Click . Click .
- Dreamweaver
- Click Ctrl+N. Choose from the Category menu. , or press
- Choose from the Basic page menu. Click .
- Add styles to the external stylesheet.
- Type a line of CSS code on the second line.
body { background-color: lightyellow; }
- FrontPage
- Click , . Click the body tag. Click .
- Click , . Select a text color (or other formatting if desired). Click 3 times.
- Dreamweaver
- Click , , . Or click , , .
- For the Selector Type, click the Tag radio button. Select the h2 tag from the Tag menu. Select the radio button Define in: (New Style Sheet File). Click .
- Select a text color (or other formatting if desired). Click .
- Type a line of CSS code on the second line.
- Click
styles2.css
. Click .
, . Type
- FrontPage
- Move a style from inline to internal (so it can be used by more
than one instance of a tag).
- Click in the upper left cell of the table.
- Switch to or view.
- Select
border: 5px solid blue;
. Press Ctrl-X to cut. Selectstyle=""
. Press Delete. - Move the cursor to the right of the
<style>
tag. Press to add a new line. Press Ctrl-V to paste. Add atable
style rule so the line looks like this:
table { border: 5px solid blue; }
- Save your changes. Test that the table still has a thick blue border.
- Move a style from internal to external (so it can be used by more
than one Web page).
- Switch to or view.
- Select
table { border: 5px solid blue; }
. Press Ctrl-X to cut. - Open
example.css
. Position the cursor outside of any style rule. Press Ctrl-V to paste. - Save your changes to both
example.html
andexample.css
. Test that the table still has a thick blue border. - In Dreamweaver, you can copy a page's internal styles to an external stylesheet. Click , , . Type a file name and click .
- Create a class selector to format groups of elements.
- FrontPage
- Click , Select from the List menu. Click .
- Type a name for the selector (e.g.
large
). - Click
3em
). Click 3 times.
, . Type
in a different font size (e.g.
- Dreamweaver
- Click , , . Or click , , .
- For the Selector Type, the Class radio button should be selected. Type the tag name
(e.g.
.large
). - Select the radio button Define in: This document only. Click .
- Type in a different font size (e.g.
3em
). Click .
- Check that the
large
style now appears in the Style menus. - Apply this style class to any element to test.
- FrontPage
- Create an ID selector to format a single element.
- FrontPage
- Click , Select from the List menu. Click .
- Type a name for the selector, starting with a # symbol (e.g.
#huge
). - Click
250%
). Click 3 times.
, . Type
in a different font size (e.g.
- Dreamweaver
- Click , , . Or click , , .
- For the Selector Type, click the Advanced radio button. Type the tag name, starting
with a # (e.g.
#huge
). - Select the radio button Define in: This document only. Click .
- Type in a different font size (e.g.
250%
). Click . - Check that
huge
now appears in the menu.
- Apply this style ID to any element to test.
- FrontPage
- Format links and create rollover effects using
pseudo-classes (a:link and a:hover).
- FrontPage
- Click , . Select from the Styles: list. Click .
- Click , . Change the color (or other formatting if desired). Click three times.
- Dreamweaver
- Click , , . Or click , , .
- For the Selector Type, click the Advanced radio button. Select from the Selector: menu.
- Select the radio button Define in: This document only. Click .
- Change the color (or other formatting if desired). Click .
- Test in a browser by viewing unvisited links.
- Repeat for to format visited links.
- Repeat for to create a rollover effect. Test by moving the mouse over a link.
- FrontPage
- Look at the W3Schools tutorial for more information and examples.
Session 3: Text Formatting
- If you are not continuing from Session 1, download the example files and link the stylesheet to the Web page.
- Use CSS lists.
- Add this code to the internal or external stylesheet and observe the effect on the
bulleted list:
ul { list-style-type: circle; }
- Change the
list-style-type
todisc
,square
, andnone
, and observe the effect for each. - Add this code to use an image for the bullets:
ul { list-style-image: url(/Content/css/tinysprout.gif); }
- Add this code and observe the effect on the numbered list:
ol { list-style-type: decimal; }
- Change the
list-style-type
toupper-roman
,lower-roman
,upper-alpha
andlower-alpha
.
- Add this code to the internal or external stylesheet and observe the effect on the
bulleted list:
- Use CSS colors.
- In the table in Section 2, highlight each word and add an inline style to use a
different background-color:
<td style="font-size: 20pt; background-color: red;">one</td>
- Try the following values:
red darkred transparent #00F #0F0 #FF0 #F00 #FF0000 rgb(255,0,0)
- Try the following values:
- In the table in Section 2, highlight each word and add an inline style to use a
different background-color:
- Use contextual selectors to apply styles only to elements that
occur within other elements.
- To make links only in the footer red, add this line of code in the internal or external
stylesheet:
#footer a { color: red; }
- To make links only in the footer red, add this line of code in the internal or external
stylesheet:
- Group multiple selectors to reduce repetitive code.
- To underline both
h1
andh2
headings, add this line of code in the internal or external stylesheet:
h1, h2 { text-decoration: underline; }
- To underline both
- Add an alternate stylesheet to a Web document, e.g. a large font
or text-only version of a page for accessibility.
- If you are not continuing from Session 2, download styles1.css and styles2.css or create from steps 4 and 5.
- Add these codes to the head section of
example.html
:
<link href="styles1.css" rel="alternate stylesheet" type="text/css" title="fancy" />
<link href="styles2.css" rel="alternate stylesheet" type="text/css" title="simple" /> - Save, open in Firefox or Netscape, and test by clicking , , or .
- Add a print stylesheet to a Web document.
- Create a stylesheet named
print.css
. Add this code to the head section ofexample.html
:
<link rel=stylesheet href="print.css" type="text/css" media="print"> - To just override a few styles, use either of these methods:
- In the print stylesheet, include the regular styles using the statement
@import url(styles.css); - Instead of using a separate print stylesheet, add the following statement at the
end of the regular stylesheet:
@media print { }
Add the print styles between the curly braces
- In the print stylesheet, include the regular styles using the statement
- Create a stylesheet named
- Add comments to CSS code.
- In
example.css
or within the<style>
tag ofexample.html
, add text between/*
and*/
marks.
/* This is a comment to explain CSS code to other people. It is ignored by all browsers. */
- In
Session 4: Dimensions, Positioning and Page Layout
- If you are not continuing from Session 1, download the example files and link the stylesheet to the Web page.
- Use CSS dimension
units.
- In the table in Section 2, highlight each word and add an inline style to use a
different font-size:
<td style="font-size: 20pt;">one</td>
- Try 15pt, 20pt, 15px, 20px, 150%, 200%, 1.5em, 2em, xx-large.
- Hold down Ctrl and scroll the mouse wheel to change the
default font size in both Firefox and Internet Explorer.
- Observe which font sizes change, and by how much. In Internet Explorer, pt and px sizes are fixed.
- In the table in Section 2, highlight each word and add an inline style to use a
different font-size:
- Use margin, padding and
border around an image, table or other block element.
↑↓ margin-top ↑↓ border-top ↑↓ padding-top margin-
left
↔border-
left
↔padding-
left
↔object padding-
right
↔border-
right
↔margin-
right
↔↑↓ padding-bottom ↑↓ border-bottom ↑↓ margin-bottom - Add lines of code to the
img#csu
rule in the stylesheet to change the padding, margin and border of the CSU logo.
padding: 2px;
/* top right bottom left */
border-top: 3px dotted red;
border-right: 5px dashed blue;
border-bottom: 3px double #F0F;
border-left: 5px groove #0FF;
margin: 2px 5px 2px 0px; - Add lines of code to the
img#csulibraries
rule in the stylesheet to change the padding, margin and border of the CSU Libraries logo.
padding: 2px; padding-left: 5px;
border: 2px solid #6c9; border-right-color: #042; border-bottom-color: #042;
margin: 0;
- Add lines of code to the
- Make an image float to the left or right of some content.
- Position the cursor at the beginning of the Section 1 paragraph, to the left of "Curabitur".
- Insert the CSU logo image. Only the first line of text will be moved to the right.
- Edit the image tag, add an inline
float
style, and see the image move to the left or right of the paragraph.
<img style="float: left" border="0" src="csu.gif" width="109" height="60">
<img style="float: right" border="0" src="csu.gif" width="109" height="60">
- Create a skip link for screen readers, but hide it from regular
browsers.
- Before the navigation bar, include a link to an anchor named content. It should
use the skip class.
<a href="#content" class="skip">Skip Navigation</a>
- After the navigation bar, include the anchor named content.
<a name="content" id="content"></a>
- In the internal or external stylesheet, define a skip class that positions the link
above the visible page.
.skip { position: absolute; top: -500px; }
- Before the navigation bar, include a link to an anchor named content. It should
use the skip class.
- Make navigation buttons using a list of links.
- Set the
list-style-type
of the list tonone
.
ul#nav { list-style-type: none; }
- If the buttons will be in a row, set the
display
of list items toinline
.
ul#nav li { display: inline; }
- Remove the underline from the list item links.
ul#nav a { text-decoration: none; }
- Add a
background-color
to the links.
ul#nav a { background-color: #ccc; }
- Add
padding
to the links.
ul#nav a { padding: 1px 5px; }
- Add a
border
to the links.
ul#nav a { border: 3px groove #999; }
- Change the
color
,background-color
and/orbackground-image
of the list item links when the user moves the mouse over them.
ul#nav a:hover { color: #f99; background-color: #ffc; }
- Add a
background-image
to the links instead ofbackground-color
.
ul#nav a { background-image: url(http://www.gregvogl.net/Content/css/gradient.jpg); }
ul#nav a:hover { background-image: url(http://www.gregvogl.net/Content/css/gradient2.jpg); }
- Set the
- Create a centered page.
- For a variable-width page, the body style should have equal but nonzero left and
right margins (pixels or percent).
body { margin: 0 10%; }
- For a fixed-width page, enclose the entire page content within a centered div, which
contains a document div with a fixed width (e.g.
780px
or48em
).
- In the stylesheet, add this line:
div#doc { width: 48em; min-width: 780px; max-width: 100%; }
- In the Web page, enclose the page content in two div tags:
<body>
<div align="center">
<div id="doc">
[page content goes here...]
</div>
</div>
</body>
- In the stylesheet, add this line:
- For a variable-width page, the body style should have equal but nonzero left and
right margins (pixels or percent).
- Create a two-column page with navigation and content.
- Create a list
<ul id="nav">
that contains a list of navigation links. (This could be enclosed in adiv
tag for consistency.) - Add a style in the stylesheet for
ul#nav
that positions the list on the left side of the page, below the header.
ul#nav { position: absolute; top: 70px; left: 10%; }
- Create a section
<div id="body">
that contains the body column of the document. - Add a style in the stylesheet for
div#body
that positions the body column to the right of the navigation column.
div#body { margin-left: 160px; }
- Create a list