alt.www.webmaster Notes for Novices

 

Simple Color Setting For Web Pages

Colours may be suggested to a target browser through the use of CSS. Note the use of the term 'suggested', the target browser may choose to ignore the suggestion and use its own colours anyway.

CSS allows each HTML element's parameters to be suggested. At the simplest level this may be the colour for a particular element to be displayed in.

A CSS definition follows the pattern:

element { style definition; style definition; ..... }

So, for example, to suggest a white background colour for the whole web page one can suggest the background-color parameter for the 'body' element like this: body { background-color : White; }

You will find the names of the parameters in any book on CSS.

The anchor element is a little more tricky, as it has sub-elements.Sub-elements are declared by a colon separating the element from the sub-element, so the hypertext link is actually the 'link' sub-element of the 'anchor' element and is refered to in CSS as 'a:link'

The following example shows how to suggest a white background with black text, with hypertext links displayed in green and visited
(previously clicked) hypertext links displayed in red:


<html>
<head>
<style type="text/css">
<!--
body {
background-color : White;
color : Black;
}
a:link {
color : Green;
}

a:visited {
color : Red;
}
-->
</style>
</head>
<body>

</body>
</html>


Matt Probert



Return to Notes for Novices  
Return to AWW Faq

W3C 4.01  W3C CSS   WAI-AAA