Skip to main content

Posts

Showing posts from November, 2008

Inheritance in CSS

CSS Inheritance An explanation of how inheritance works in CSS and why CSS doesn't need Object Oriented style inheritance. Introduction Many newcomers to CSS are confused by inheritance; this is often because they come from a background in object oriented (OOP) programming and expect CSS to work in a similar way. This document attempts to explain CSS inheritance and present alternatives to OO-style inheritance to demonstrate why it is not necessary. CSS Inheritance CSS inheritance works on a property by property basis. When applied to an element in a document, a property with the value 'inherit' will use the same value as the parent element has for that property. For example, given this style sheet: `.foo { background-color: white; color: black; } `.bar { background-color: inherit; color: inherit; font-weight: normal; } And this HTML fragment: div class="foo"> Hello, world. This is a very short paragraph! `div> The background colour of ...