lecture menu |
lecture 2: cascading and inheritanceYou are not obliged to define every possible property of every tag you use in the style sheet. Browsers always get style information from somewhere. If no other information is provided, the browser "falls back" upon what are known as its default settings This paragraph, for instance, should (with the exception of the background colour) be rendered in your browser's default font, colour and size.You can see the difference (and notice also the loss of the small left-hand margin, which you can also define with styles - we will talk about this in lecture 4). There is an "order of precedence" with styles. This is known as the cascade (hence the full name of the technique: CSS for Cascading Style Sheets). It is worth becoming aware of the cascade as it can help suggest to you why your style is not looking as you expected.
Bear in mind that certain tags inherit styles off other tags higher up in the hierarchy. You can see this with the examples. In each case the background-color property is only defined once, in the <body> tag. It is not necessary to define this for the other tags as each of them "inherits" the property from the <body> tag. The rules are not hard-and-fast but in general tags nested within other tags will inherit properties from them, unless you specify otherwise. This idea will hopefully become easier once we've discussed block-level and inline tags: and that is the subject of the next slide. |