Learn HTML step-by-step from A to Z or improve your professional skills.  Home HTML and CSS Tutorials Conquering Cascading Style Sheets
Your Ad Here

Conquering Cascading Style Sheets


If you're relatively new to Web design and HTML, this tutorial will help you gain an understanding of the role that Cascading Style Sheets (CSS) can play in describing how your webpage should look.

This tutorial is the first part of a three-part series on style sheets, including:

  • Part 1: Beginner (this Web article): Covering CSS definitions, HTML elements, classes, and pseudo-classes
  • Part 2: Intermediate (Layers magazine, January/February 2006): Navigation and links, styles for tables, and background images
  • Part 3: Advanced (Layers magazine, March/April 2006): DIV properties and CSS-based layout

Step 1

STEP 1 Start with Some Text

Open the file index.html. Start with some plain text on your page. Without any CSS instructions, GoLive will display the text as black, Times Roman, at approximately 14 points. This is because this is the average default setting of most Web browsers.

Step 2

STEP 2 Assigning HTML Elements

Before creating some style sheet definitions, let's first style the text with basic HTML mark-up. Select the text “ATTRACTIONS,” then on the Options Bar at the top, from the Set Paragraph Format pull-down menu, select Heading 1. This creates an HTML element named <h1> (which stands for Heading 1). GoLive will also render this to the default settings of most Web browsers.

Step 3

STEP 3 Adding a Link to Text

Next, select the “Learn more” text, and in the Inspector palette, enter a pound sign (#) in the Link field. This will create linked text in the document. This also creates an HTML element named <a> (which stands for anchor). Anchors are the most common way to make items “clickable” in webpages.

Step 4

STEP 4 A Look Under the Hood

Click on the Source Code Editor button at the top of your window to switch to Source view and look at the code we have generated so far. The green arrows indicate the beginning and end of the heading <h1> element, and the orange circles indicate the beginning and end of the anchor <a> element. Notice that the “ATTRACTIONS” text is inside of the heading element, and the “Learn more” text is inside of the anchor element. This is important to note because when we make our CSS definitions for headings and anchors, only the text inside of these tags will be affected.

Step 5

STEP 5 Open the CSS Editor

Click on the Layout Editor button to switch back to Layout view. Then, click the Open CSS Editor button at the top right of the document window to bring up the CSS Editor for this page. You can have CSS definitions in two places: inside the webpage you are working on, or in a separate CSS document that is linked to your page. The advantage of linking to a CSS document is that you can use one CSS document on all of your pages, and exercise global control of your website's look from one place! So, we're going to opt for this.

Step 6

STEP 6 Linking to a CSS Document

In the CSS Editor window, click the button to Create a Reference to an External Style Sheet File. Next, you will see an empty reference created in the area to the left. Select it, and use the Fetch URL button to point-and-shoot to the stylesheet.css document in the site window. Then close the CSS Editor window.

Step 7

STEP 7 Create a CSS Definition

Open the file stylesheet.css. We are going to redefine some standard HTML elements. Click on the Create a Style That Applies to Markup Elements button, and select h1 from the pop-up menu. This will allow us to redefine how the Web browsers will render text inside of the <h1> element tags.

Step 8

STEP 8 Assign Properties to a Definition

Select the <h1> element in the definition list to the left. Next, click on the Font Properties tab. Choose 12px for the size. Double-click on the Color field to bring up the Color Picker and choose a brownish color. Then, click the Create New Font icon at the bottom right of the window and select Arial as the font from the pop-up menu.


Step 9

STEP 9 Assign Additional Text Properties

Now, select the Text Properties tab and enter 20px for Letter Spacing. As you make changes, you'll see your changes happening in real time.

Step 10

STEP 10 Style Your Links

Make a new definition for the <a> element. Select the a:link item from the Create a Style That Applies to Markup Elements button's pop-up menu. (If the buttons shown here don't appear along the top of your window, click below your new element to get back to the front screen and turn on the checkbox for Show These Buttons at Top.) This controls the way a link looks in your page. the “:link” is actually a pseudo class, meaning a subset of the <a> element. We'll do more with this in the next step. Once you make the new a:link element, select the Font Properties tab and choose Red from the Color pop-up menu.

Step 11

STEP 11 Set Rollover Colors for Links

Make a new element, just as in Step 10, and select the a:hover. This is another instance of the anchor element <a>, but with the pseudo class of hover. This means that the properties you select with this definition will only occur when you hover (move your mouse) over the link. Click the Font Properties tab and select a light blue color in the Color field. Save your style sheet document (File>Save), and choose the Preview button in your document. Roll your mouse over the link to see the :hover pseudo class in action!

Step 12

STEP 12 Set Properties for the Page

Let's make yet another element definition. Same process as in Step 10, but choose <body>. In the Font Properties tab, select Blue from the Color pop-up menu, and Yellow from the Back Color pop-up menu. Type 12px for Size, and choose Times from the Create New Font pop-up menu. As before, you will see the changes reflected immediately.

Step 13

STEP 13 Make a Custom Class

Now we're going to invent our own definition item. Click on the Create a New Class Style button. This will create a new item in the left area called “.class.” Class items are items you can name anything you want, as long as it starts with a period (.). Let's name it “.heading” and give it a Size of 18px in Font Properties. From the Style pop-up menu, select Italic.

Step 14

STEP 14 Assign Your Custom Class

Finally, select the text “Night Life” in your webpage. Bring up the CSS palette under the Window menu. You will see a listing in this palette of every custom class you create. Turn on the checkbox under Inline Style next to the “heading” item. GoLive will also show you a preview of what the text will look like with this style selected in the preview pane of the CSS palette. If you look at the Source view again, you'll notice your custom CSS tags inserted into the code <span class=“heading”> around the Night Life text.

Courtesy of Layers magazine.



About the Author:

Chris Converse is a versatile, award-winning designer who integrates creative strategy with sophisticated design—for the kind of results clients want. His expertise is a perfect balance between traditional and interactive mediums, including print, interactive, DVD and CD-ROM production, animation, corporate identity, branding, and photography. A short list of clients includes: Adobe Systems, AOL, Comcast, Campbell’s, Pepperidge Farm, Moore College of Art, University of Pennsylvania, Breastcancer.org, Independence Blue Cross, AmeriHealth, Johnson & Johnson, Wyeth, Pfizer, AstraZeneca, Bristol-Meyers Squibb, Accuvue, McNeil Consumer Health, and many more.

Author's URL: Chris Converse
Thank you for voting.
Rate this Materials:
Bad 
1 2 3 4 5 Excellent
print this page subscribe to newsletter subscribe to rss

HTML is Hyper Text Markup Language that is used to make hypermedia and hypertext documents for the Web. More HTML and CSS: Most Popular Materials | Fresh Materials | More HTML Tutorials at Markuptutorials.com

Add comments to "Conquering Cascading Style Sheets"

Only registered users can write comment

No comments yet...