Skip to Content
CSS: The Missing Manual, 4th Edition
book

CSS: The Missing Manual, 4th Edition

by David Sawyer McFarland
August 2015
Beginner to intermediate
718 pages
20h 46m
English
O'Reilly Media, Inc.
Content preview from CSS: The Missing Manual, 4th Edition

Chapter 5. Managing Multiple Styles: The Cascade

As you create increasingly complex style sheets, you’ll sometimes wonder why a particular element on a page looks the way it does. CSS’s inheritance feature, as discussed in Chapter 4, creates the possibility that any tag on a page is potentially affected by any of the tags that wrap around it. For example, the <body> tag can pass properties on to a paragraph, and a paragraph may pass its own formatting instructions on to a link within the paragraph. In other words, that link can inherit CSS properties from both the <body> and the <p> tag—essentially creating a kind of Frankenstyle that combines parts of two different CSS rules.

Then there are times when styles collide—the same CSS property is defined in multiple rules, all applying to a particular element on the page (for example, a <p> tag style in an external style sheet and another <p> tag style in an internal style sheet). When that happens, you can see some pretty weird stuff, like text that appears bright blue, even though you specifically applied a class style with the text color set to red. Fortunately, there’s actually a system at work: a basic CSS mechanism known as the cascade, which governs how styles interact and which styles get precedence when there’s a conflict.

Note

This chapter deals with issues that arise when you build complex style sheets that rely on inheritance and more sophisticated types of selectors like descendant selectors (Styling Tags Within Tags). The ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

HTML5: The Missing Manual, 2nd Edition

HTML5: The Missing Manual, 2nd Edition

Matthew MacDonald
Grid Layout in CSS

Grid Layout in CSS

Eric A. Meyer

Publisher Resources

ISBN: 9781491918043Errata Page