![]() |
WEB DESIGN SKILLSModule Study Guide
|
A style sheet is a set of commands that control the style of a web document. Use of a style sheet gives designers more control over the look of their web pages without affecting the structure. Style sheets define typographic control and page layout such as fonts, margins, spacing, colour etc.
Use of style sheets can ensure quicker download time for your pages and complete control of all design attributes across multiple pages.
However due to lack of web standards the support for style sheets is not consistent across browsers. No browser yet supports all of the CSS capabilities.
Style sheets can be placed in three different places:
We shall be creating an external Style Sheet in this exercise. As a separate document to your HTML pages it will need to be attached to them and STORED IN YOUR ROOT FOLDER.
A stylesheet allows you to redefine the appearance of standard HTML tag objects
such as <p> (paragraph) or <h1> (heading1).
e.g. Suppose you want to set the appearance of all 'paragraph' text within your web pages. You could use a style-sheet definition such as:
p {
font-family: arial;
font-size: 100%;
color: #ff0066;
font-weight: bold;
}
Notice the use of curly brackets, colons and semi-colons, which must all be
used as indicated here (newlines and indentation are optional). In this case
all text within <p> and </p> tags
would appear in 'Arial' font, 100% size (other text may be larger or
smaller than this), of colour #ff0066 (red) and weight 'bold'.
There are other text attributes to which you can assign values:
text-indentbackground-colorborder (color, style and width)text-decoration (line-through, underline, overline, none) margin-left (or right, top, bottom)height, width You can apply this kind of style to any tag you want, although of course not all definitions would have any meaning - changing the font-size, for instance, of a <br> tag would not have any effect.
However, you may not want to alter the appearance of all the text covered by a certain tag, so for further control, stylesheets contain 'classes' which also have attributes to which you can assign different values.
e.g
.pink {
font-family: verdana;
font-size: 12px;
color: #550066;
font-weight:
bold
}
This looks just like a tag definition, but instead of a tag we use a class
name. The class name here is .pink (note
the full stop before the name).
pages can
be allocated to the class .pink in this way:
<div class="pink">
<p>A paragraph of text</p>
.....................
</div>
(no full stop here, but the class name is in quotes)
Here we have used the <div> tag to identify the section of text. This allows
the use of other elements within the specified style, such as tables or lists.
For text of less than a paragraph:
<p>Ordinary text<span class="pink"> Pink text</span> More
ordinary text
which looks like this:
Ordinary text Pink text More ordinary text
Notice that the CSS definitions go in the style sheet document, whilst the HTML codes go in the ordinary web pages. A single style sheet can be attached to many different web pages, thus making it easier to alter the appearance of all the pages in one go.
Note: Although it is quite easy to set the font size of any text to a fixed
value (e.g. font-size: 12px) it is not considered to be good design practice,
as this means that the end user cannot alter the text size for their own convenience,
making it bad news for viewers with a sight disability.
IDs are very much like classes, and work in much the same way. The differences are:
<div id="mystyle1"><link
rel="stylesheet" href="mystyle.css" type="text/css">
Against 'Selector Type' choose 'Tag' and in the 'Tag:' box at the top select
a tag which you have used in your web page, such as <p> or <h2>.
The 'Define in' box should have the name of your CSS file ('test.css').

Because styles can be defined in different places (see above) there can be conflicts when the definitions of a particular entity are differently defined in those places. For example, suppose the external style sheet says that all paragraph text is in 'Arial' font, but in the head of a document, it says that it should be in 'Times' font. Which would it be?
The 'cascading' rule says that in circumstances such as these, the most local definition applies. In other words, in the example above the definition in the document head would take effect, because that is more 'local' than the external style sheet definition. This makes it possible to make generic site-wide definitions which can be overwritten locally if necessary.