Thomas Hardye Science College

Web Design Workshop

  • Home
  • World Wide Web
  • Introducing HTML
  • Introducing CSS
  • Dreamweaver Interface
  • Top Tips
  • Putting it all together!
  • Design Principles
  • Accessibility
  • Useful Links
  • Glossary

Link to Glossary If you see this symbol in the text it is a Link to Glossary with more detailed information

  • Activity 9
  • Activity 10
  • Activity 11
  • Activity 12
  • Activity 13
Optional Activities
  • Activity 14
  • Activity 15
  • Activity 16

Introducing Cascading Style Sheets - CSS

Introduction

Well as you can see coding a page like the one you made in the last section using simple tags, adding links and images was fairly straightforward, but it doesn't look very pretty does it? Most web pages we view on the Internet have some design and formatting, good or bad, instead of the default you see in your 'Notepad' page.

Web pages used to be made look more attractive or formatted by adding attributes Link to Glossary into tags like:

	<p align="center">
<font size="16pt" face="Georgia,"Times New Roman", Times, serif"
color="#FF0000" ><i><b> Text Here!</b></i></font></p>

The code above will make centred red text in Georgia font which is bold and italic, like the text below.

Text Here!

What a lot of code for two words!

But the text has actually been styled with CCS or Cascading Style Sheets

	<p class="textstyle">Text Here!</p>

Now that is better.

This is the how most web sites are now constructed by separating content and style, which was one of Tim Berners-Lee original goals, HTML was designed primarily as a markup language for content rather than style. Although it doesn't seem a very important distinction, it is crucial to the continuing development of the www and the growth of alternative viewing devices such as mobile phones and PDA'S.

HTML code using attributes in the page does not comply to the latest W3C web standards and the tags have now been deprecated although they are still widely in use. Have a quick look at this web site which explains it more fully www.codehelp.co.uk

Activity 9

The following web site shows how different styles can be applied to plain text and how they give a completely different look to the same text web page.

Go to CSS Zen Garden and before you look at the different designs click on download the sample html file on the left side of the page to open it (It's just like your boring website you made earlier!). This is what the HTML document looks like without any styles applied.

Click the back button and then select different designs from the list on the right. They use the same HTML document that we just looked at but different style sheets have been applied.

This website complies with xhtml, CSS web standards and Level 3 accessibility standards to prove that standard and accessible sites don't have to be boring.

Advantages & Disadvantages of CSS

Advantages of CSS

  • Separating content and style gives the designer much more control over their website and gives alternatives for a better viewing experience, including people with accessibility problems.
  • Another good reason is to imagine you have designed a 100 page website and the boss decides he/she doesn't like the font in the website and then having to go into every page and changing the fonts! With an external style sheet you can change a website by altering one file, a lot easier and quicker!
  • You can create a consistent design and style to your website.
  • Other advantages are that because there is a separate style sheet, without all the attributes tacked on the pages have a smaller file size and so are much quicker to load in a Browser.

Disadvantages of CSS

  • Browser support has been a bit patchy but with the release of later Browsers this is becoming less of a problem.

Activity 10

Take a look at the Science College website it has some features for better user experience and accessibility.

Try out the style switcher for the text sizing in the top right hand corner, this is done with some JavaScript code and different style sheets, as you click the Text Size buttons different styles are applied and different sized text is shown.

Close the Science College website and go to File > Print Preview in this page you will see that a print style has been applied which strips out any unnecessary text and styling for the print version.

Finally take a look at BBC news it has versions of its web pages for mobile phones and PDAs and these again use style sheets to achieve this, it also has a low graphics version of the website which is another style sheet and a good web accessibility feature.

As you can see it gives the designer much more scope for the their websites, making them more usable and accessible to all.

Another change in web design is the use of styles for the layout of pages, for years many pages have been designed using tables and it was considered the only way to style complicated designs. Again this made for bigger file sizes, tables were introduced for tabular data not for design. Many pages are still constructed this way.

We will not be going into CSS Layout as again it would need a course on its own and they can get complicated while very frustrating to get them just right, as I know from experience. With this sort of level of CSS it is vital to test the websites in other Browsers, if you use IE6 it is quite forgiving and when you look at it in another browser it can be all over the place, again this is from experience! This website, THS Intranet, The Science College and some of the DASP websites have been constructed using CSS layout techniques.

Top of Page Top

CSS structure - A quick guide

How are styles used?

There are three ways in which styles are added to web pages:

1. Inline styles which are embedded into the page

		<p style="color:#FF0000">Inline style</p>

This paragraph tag will have red coloured text. Inline styles are not really encouraged in good web practices.

2. Document level styles in the head of the document.

	<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Document Level style</title>
<style type="text/css">
<!--
p {
color: #CC0000;
}
-->
</style>
</head>

All the paragraph tags will have red text in them.

3. External style sheets, you can have more than one in a website.

	 p {
color: #CC0000;
}

This will be saved as a separate document as file_name.css and the link is put in the head of any web page where you require this style in a website. Using this link:

		<link href="file_name.css" rel="stylesheet"
		 type="text/css" />

All the paragraph tags in any page that has this CSS file attached to them will have red text in them. This is the preferred way of attaching styles as it separates style from content.

Questions & Answers on CSS

What is cascade in CSS?

As you can see styles can be specified in a number of ways inline, document level or external. This could cause conflict within a document using these different methods of using styles. So the cascade refers to the way the styles have precedence over one another. The style nearest the element to be styled takes precedence over any other styles.

  1. Inline style
  2. Document level style
  3. External style sheet
  4. Browser default

So in the list above the inline style will take precedence and cascade down to the browser default if there are no styles

What is the rule structure of CSS?

We will not be going too much into the hand coding of style sheets as they can be handled in Dreamweaver, but it is useful as with HTML to know what goes on behind your own pages by using Notepad editor! Also we will not be using inline or page styles only external style sheets although they can be useful if you want to have a particular style just on one page in your website.

What selectors are there?

Here are the selectors we will be using in our activities, there are others but we will not be looking at them in this Workshop. We will be doing an activity shortly where we will use these selectors.

tag selectors - Will apply a style to any HTML element that matches the selector. For example if you want all Heading 6 tags in your site to be red in colour, italic text, text size 80% and centered you would write a CSS rule as follows:

		h6{
			color:#FF0000;
			style: italic;
			font-size: 80%;
text-align: center; }
Heading 6

class selectors can be used to select any HTML element that has a class attribute.

	.highlight {
background: #FFFF66
}

This word is highlighted

<p>This word is <span class="highlight">highlighted</span> </p>

This whole paragraph is highlighted

<p class="highlight">This whole paragraph is highlighted </p>

You have to add class selectors rather than them being automatically applied as above. To define a class you need to have a period at the beginning of the name as in .highlight it is best to name it something relevant to the style so it will be easy to find if you want to apply the style again.

id selectors are similar to class selectors but can only be applied to one element on a page. They are useful for CSS layout where you would only require for example on left column or one right column. To define an id you use the # hash symbol in front of the name.

pseudo-classes are used to apply special effects to some selectors such as hyperlinks. The link styles must be written in the following order to get the effect you require.

		a 	{
color:#000099;
} a:link { color:#000099; }
a:visited { color:#3366CC; }
a:hover { color:#990000; }
a:active { color: #000099; }

What media types does CSS styles support ?

Media types allow you to specify how your documents look in different media. You looked at print media type in Activity 10.

  • all - Used for all media type devices
  • aural - Used for speech and sound synthesizers
  • braille - Used for braille tactile feedback devices
  • embossed - Used for paged braille printers
  • handheld - Used for small or handheld devices
  • print - Used for printers
  • projection - Used for projected presentations, like slides
  • screen - Used for computer
  • tty screens - Used for media using a fixed-pitch character grid, like teletypes and terminals
  • tv - Used for television-type device

Some of the media types are not well supported in Browsers, but will be in the future.

Making some simple changes to a style sheet.

Attaching an external Style sheet

Before we can make some changes to a style sheet we need to attach it to a page where we can view any changes we have made.

Activity 11

Copy & Paste the project_1 folder in the Workshop folder into your folder.

Open the project_1.htm page as you will see there are no styles attached. We will add the external style sheet link to add some formatting to the page.

Right click your mouse and View source you can now edit this page.

Under the title put the following code:

<link href="styles/project1_style.css" rel="stylesheet" type="text/css" />

Save the Notepad document and close it. Now refresh refresh button your browser and you should have some styles!

Leave the page open, and minimize it to your task bar.

Working with a style sheet

Font styles

Activity 12

Now go back to your project_1 folder in your own folder and open styles > project1_ style.css by right clicking it and Open With > Notepad. This will open your external style sheet for the page you just added the link to.

We will now experiment with some of the styles.

We will start with the Headings you should be able to find them on your style sheet easily enough they are below the comments /*Define styles for the different headers*/

NOTE: Anything written between /* Text here */ are notes and will be ignored by the Browser.

Change some of the font sizes by changing the percentage Save your file and Preview in your web page. If you have minimized it to the Task bar just press refresh and you should notice the changes you have made.

The font family Arial, Helvetica, sans-serif has been declared in the body style but you can change the fonts in different elements.

In the headings again try changing the font family.

  • Press return after the font size to go onto a new line
  • Type in font-family: (don't forget the colon) and choose a set of fonts from the list below (why we use more than one font in a declaration can be found on the Top-Tips page
  • "Times New Roman", Times, serif
  • "Courier New", Courier, mono
  • Georgia, "Times New Roman", Times, serif
  • "Comic Sans MS", Arial, sans-serif

Always remember to close the rule with a semi-colon.

NOTE: When there is white space in a font it must be quoted with either single or double quotes eg. "Times New Roman"

Save and Preview in your Browser as before

Don't close Notepad or you Browser yet

Of course you can change the font styles on paragraphs indeed any text and even single words if you wish but don't use too many different fonts. Why? Go to the Tops Tips page

Colours

Activity 13

We will now change text colours with styles

This is fairly simple all you need to remember is that when you declare the colour you type color (US spelling!)

So in any of your headings under the last rule type:

color:

Then choose a colour from the colour chart provided in your folder. There are a number of ways to declare a colour but we will be using Hexadecimal notation Link to Glossary for the colours ie: #FF0000 which is red, remember to add the hash # sign at the front.

So your rule to change the text to red will be:

color: #FF0000;

Have a go at changing colours in your headings. You can even change the background colour of the page, the page border and text colour in the body style.

Save and Preview as before

Don't close Notepad or you Browser yet

Top of Page Top

Optional Activities

Link Styles & List styles

You can see by the left hand navigation of this page that you can do a lot with lists. You can just style the bullet on a list with an image or just change from disc to square bullet etc. But where they are very useful and can be styled in lots of different ways is with hyperlinks. The Science College website navigation is just made up of a list of links with styles applied. The Prince of Wales navigation is also a list and links. You can use CSS to make rollover navigation where we used to use Flash or Javascript. They are much more simple code and you can be confident that people can see them as you intended. They can be a simple or a complex as you wish to make them.

In the next Activity we will change the look of some link styles.

Links

Activity 14

At the moment the links at the bottom are pretty boring. There are a number of things you can do to change them!

Try some of these out remember to Save your Notepad file and Refresh your browser each time so you can view your changes.

  • You can change the font-size if you wish
  • Change the colours of the different elements of the a: declarations, try it with the help of your colour chart.
  • By default a link has an underline you can change this in a number of ways by using the selector text-decoration:. Here are some you can try -

text-decoration:none;
text-decoration:underline;
text-decoration:overline;
text-decoration:line-through;

  • You can also have a background colour to your different elements of your link. Add background: #FFFF66; to the a:hover declaration. Give the others a background colour if you wish.
  • So the background colour doesn't just cover the text you can add some padding to the link. In the a declaration add padding: 2px; When you change this declaration it will effect all the a: declarations.
  • If you would like to try and add an image to your links and list go to the next activity where it will show you how!

Don't close Notepad or you Browser yet

Lists

Activity 15

In this activity we will change some list styles by putting in different images for different jobs.

I have already declared three styles for formatting an unordered list in project_1style.css. Have a look at how this is done under the comment /* List styles with image*/

Now you will have a go at changing the different styles in your page. Maximize or Open your project1.htm page and right click > View Source which opens the page in Notepad.

Locate the list you want to add the style to, it will look like this:

    <ul>
<li><a href="#">Information</a></li>
<li><a href="#">Contact Us</a></li>
<li><a href="#">News</a></li>
<li><a href="#">Links</a></li>
</ul>

In the <ul> tag at the top type class="arrow"

    <ul class="arrow"> 

Save your Notepad file and minimize it to the toolbar

Refresh your web page and you now should have an arrow as your bullets!

Try changing the different styles in the class I have declared arrowright and arrowdown classes.

NOTE: Unlike naming files for websites, where you can use an underscore, when you name styles never use an underscore, either use a dash or have no space between words. So you could have arrowdown or arrow-down

Don't close Notepad or your Browser yet

Background images

Activity 16

project1.htm has a background image in it and has been declared in the body style. If you look at the style sheet you will see how it is declared in the background rule along with the colour.

  • url(../images/butterfly.gif) - This is where the image can be found relative to the style sheet.
  • no-repeat - This means the image will not be repeated
  • right top - This places the image in the right (horizontal first) top corner

Try moving the image on the page by changing right to left and top to bottom and Save and preview your page in between to see what happens.

Note: You can also use pixels and percentages to move the image about on the page, that way you can get more precise positioning.

I have added another image to the project 1 images folder called oak_leaf.gif try putting this one in instead of the butterfly.

Once you have done this try changing how it repeats itself. The choice is:

  • no-repeat
  • repeat
  • repeat-y
  • repeat-x

The positioning will not be necessary with the last three in the list so you can remove them when you have a go.

Again Save and Preview your page in between each alteration to see what happens.

Close your Browser and Notepad

This is a quick introduction, and hopefully it has given you an insight of what goes on behind a webpage with a style sheet. If you would like some more information on CSS I have put some useful links on the links page on this site.

We will now take a look at the Dreamweaver interface before we put it all together and work on a small website project, adding and updating and doing those jobs that you will do on your own websites.

Next section the  Dreamweaver interface >>

Top of Page Top

Web Design Workshop - Science College/DASP 2007 Marilyn Peddle & Richard Scott