Contextual selectors in CSS2

I'm wondering why styling an element inside a specific class like:

.reddish H1 { color: red }

      

shown as an example of the correct syntax in the CSS1 specification under Contextual Selectors:

Cascading Style Sheets, Level 1

but it is not shown as an example in the CSS2 spec:

Cascading Style Sheets, Level 2

At least I can't find an example. Are the syntax rules for this changed in CSS2, or is it just deduced as the correct syntax?

+1


source to share


2 answers


This syntax is correct, but the example might change for several reasons.

First, it's not a good idea to name classes a description of what they do. In case, the .reddish h1

CSS example shows that it should be colored red. However, if h1

it actually turns blue on a later design change , then

.reddish h1 { color: blue; }

      



little sense. You should name your classes by their function or purpose on the page, not what style they should represent.

Secondly, it is not recommended to use keywords for colors as the color you get depends on the browser's interpretation. Instead of "red", you must use the hex code "# ff0000" to get the exact color in all browsers. (red might not be the best example here, but there are some weird color keywords).

While neither of these things are all bad, they both might add why the example changed in the spec.

+3


source


You must write elements in lowercase (h1, not H1).



+1


source







All Articles