Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

Question

css styles- order

Feb 2, 2012 6:55PM PST

When deciding on the order of importance with styles, what must be taken
into account?

Discussion is locked

- Collapse -
Answer
Re: styles
Feb 2, 2012 7:01PM PST

If you put them in the wrong order, you get the wrong results. For any property, the latest is valid and the earlier are discarded. So put the most general first, and the most specialised last.

Kees

- Collapse -
Answer
Cascading.
Mar 13, 2012 7:50AM PDT

CSS rules "cascade." The follow on from one another. If you look at the following code, you'll see that the italic tag is assigned two separate styles:

i {color: green;}
i {color: red;}


This would result in the italic words appearing in red, as red is the latest given rule in the stylesheet.

Likewise, the more specific rule always overwrites the more general. To illustrate, if your italic word is contained within a paragraph and this rule is added to the stylesheet...

p i {color: blue;}

...then the word would appear blue (not red) because it is being targeted more directly.

Chapter 10 in this book has a good explanation about cascading styles:
http://www.htmlandcssbook.com

Ivy