| |||||||||||
Click the picture below for more books on CSS
|
Inheritance of Styles In many cases, child elements acquire or inherit the styles of their parent elements. For example, suppose a style has been assigned to the
The headline is important!In this case, the child
The headline is important!Inheritance starts at the top-level element. In HTML, this is the To set default style properties for all elements in a document, you can specify a style for the
A few style properties are not inherited by the child element from the parent element, but in most of these cases, the net result is the same as if the property was inherited. For example, consider the background color property, which is not inherited. If a child element does not specify its own background color, then the parent’s background color is visible through the child element. It will look as if the child element has the same background color as its parent element.
The above table is defined as follows:
The “inherit” value Each property (such as text-indent, text-align or text-shadow) may also have a specified value of “inherit”, which means that, for a given element, the property takes the same computed value (described below) as the property for the element’s parent. The inherited value, which is normally only used as a fallback value, can be strengthened by setting “inherit” explicitly. In the example below, the “color” and “background” properties are set on the BODY element. On all other elements, the “color” value will be inherited and the background will be transparent. If these rules are part of the user’s style sheet, black text on a white background will be enforced throughout the document. BODY { * {
Computed values Specified values may be absolute (i.e., they are not specified relative to another value, as in “red” or “2mm”) or relative (i.e., they are specified relative to another value, as in “auto”, “2em”, and “12%”). For absolute values, no computation is needed to find the computed value. Relative values, on the other hand, must be transformed into computed values: percentages must be multiplied by a reference value (each property defines which value that is), values with relative units such as “em”, “ex” and “px” must be made absolute by multiplying with the appropriate font or pixel size, “auto” values must be computed by the formulas given with each property, certain keywords (“smaller”, “bolder”, “inherit”) must be replaced according to their definitio ns. In most cases, elements inherit computed values. However, there are some properties whose specified value may be inherited (e.g., the number value for the “line-height” property). In the cases where child elements do not inherit the computed value, this is described in the property definition. If you want to know more about units, please read the article: Units Used in CSS.
Comments
Is the "px" really relative?
- Norman Jackson Yes, it is. The length of a pixel depends on which machine you use as well as which browser you use. For example, your page with WIDTH:550px is wider on Opera than on Internet Explorer. For more information, please visit this page: Units Used in CSS. - Akira
| ||||||||||