[Guide] Selector grouping You can group selectors so that the grouped selectors can share the same declaration. Separate the selectors that need to be grouped with commas. In the following example, we group all the header elements. All the caption elements are green. H1,h2,h3,h4,h5
Grouping of selectors
You can group selectors so that the grouped selectors can share the same claims. Separate the selectors that need to be grouped with commas. In the following example, we group all the header elements. All the caption elements are green.
H1,h2,h3,h4,h5,h6 {
Color:green;
}
Inheritance and its problems
Depending on the CSS, child elements inherit attributes from the parent element. But it doesn't always work this way. Take a look at the following rule:
Body {
Font-family:verdana, Sans-serif;
}
According to the above rule, the BODY element of the site will use the Verdana font (if the font exists in the visitor's system).
With CSS inheritance, child elements inherit the attributes owned by the highest-level elements (in this case, the body) (these child elements such as P, TD, UL, OL, UL, Li, DL, DT, and DD). No additional rules are required, and all child elements of the body should display the Verdana font, as are the child elements of the child element. And in most modern browsers, it is true.
But that is not necessarily the case in the bloody era of browser wars, when support for standards is not a business priority. For example, Netscape 4 does not support inheritance, it ignores inheritance, and also ignores rules applied to the BODY element. Ie/windows until IE6 there is a related problem, the font style inside the table is ignored. What are we supposed to be doing?
Treat Netscape with Kindness 4
Fortunately, you can deal with the Legacy browser's inability to understand inheritance by using the redundancy rules we call "be Kind to Netscape 4".
Body {
Font-family:verdana, Sans-serif;
}
P, TD, UL, OL, Li, DL, DT, DD {
Font-family:verdana, Sans-serif;
}
4.0 browsers do not understand inheritance, but they can understand group selectors. This will waste some of the user's bandwidth, but if you need to support Netscape 4 users, you have to.
Is inheritance a curse?
What if you don't want the "Verdana, Sans-serif" font to be inherited by all the child elements? For example, you want the font of the paragraph to be times. No problem. Create a special rule for P so that it will get rid of the rules of the parent element:
Body {
Font-family:verdana, Sans-serif;
}
TD, UL, OL, UL, Li, DL, DT, DD {
Font-family:verdana, Sans-serif;
}
p {
Font-family:times, "Times New Roman", serif;
}