11. Backward Compatibility and CSSWe know that older browsers (version 3 or older of all the major browsers) don't support style sheets. How can we design sites based on style sheets for appearance that don't look too plain in older browsers? It's a complex issue, but one I want to discuss a little in this lesson. Along the way we'll learn about the one important kind of selector we haven't yet seen. Legacy CodeYou've got a long-standing site, which uses presentational HTML (elements like Let's look at the problem in a little more detail. Recently, I remember this question from the style sheets newsgroup "If I have a web page that uses presentational markup (like the FONT tag) then style sheets don't override these. I have to remove them. Why is that?" Let's take a look at the HTML here, to see what is really happening. Imagine we have the following HTML in our page
and a style sheet rule that says
pop quizWhy will a browser still show the paragraph in Arial, not in Verdana? Think about it. The text is in fact in a font element, which itself is contained inside the paragraph. The rule selects the paragraph, but the text doesn't inherit the style of the paragraph, because there is some more specific information associated with the How do we make our paragraphs Verdana? pop quizWhat happens if we also have
Suddenly, all our headings are also in Verdana. Not a good outcome. How can we get around this? Logically, we'd like a rule that selects only And we can do exactly that, which is the last important subject we'll cover in these lessons. ContextSo far, we've seen that rules can have
The last selector we are going to learn about in these lessons is the Contextual Selector. It lets us make a rule that only applies to an element when it is contained inside another element. For example The form of these selectors is simple, just a list of the selectors, in order of containment, separated by a space.
Exercise 1Create a series of rules that achieve our desired effect of having all the paragraphs in Verdana, and all the Headings (just do level 1, 2, and 3) in Times. Answers at the foot of the lesson. Here is a slightly modified version of the example web page for testing whether these rules are working. Create a new file, paste it in, and save it in the same folder as the other web page.
NextWe have really covered some ground now, and we are coming to the end of our lessons. By now, we have covered most commonly used ways of selecting elements on a page, and many of the key styles at our disposal with style sheets. At the end of the lessons there are suggestions of where to go from here. Answer to Exercise 1
Did you add the generic font family as recommended? (C)1997-2002 Western Civilisation Pty. Ltd.
|