Managing the CSS Cascade
There are times when the CSS cascade becomes a pain in the ass. When we want to revert the value of a property to its default (before we added any other value for the property in the current element or any ancestor up the chain) we have to remember the property but also what the default value is. CSS provides several mechanisms to handle inheritance. We'll discuss several ways to work with the cascade to make it do what we need. ## initial The newest (to me) way to reset is the initial value. The `initial` CSS keyword sets and element to its initial value. It is allowed on every CSS property and causes the element for which it is specified to use the initial value of the property. On inherited properties, the initial value may be surprising and you should consider using the inherit, unset, or revert keywords instead. Test the hell out of this keyword. ```markup
this text is red this text is in the initial color (e.g. black) this is red again
``` One thing to be aware is that the initial value may not be the same across browsers. This is specially important when working with fonts as the [default font](https://www.granneman.com/webdev/coding/css/fonts-and-formatting/web-browser-font-defaults/) is not necessarily the same in all browsers. ## inherit The `inherit` CSS value uses the value of the parent element's property (defining the parent as the parent element in the document tree, even if it's not the containing block). It is allowed on every CSS property. In the following CSS fragment the h2 elements that are children of #sidebar will inherit the color of its parent. The stylesheet defines another container (`div#current`) with a different color. ```css /* make second-level headers green */ h2 { color: green; } /* leave those in the sidebar alone so they use the parent's color */ #sidebar h2 { color: inherit; } div#current { color: blue; } ``` In the following HTML fragment the sidebar's h2 element will be blue, the color of the parent. ```markupSidebar Title
This text is red
This text is also red