

If you use inherit on any of the shorthand properties (like font or list-style), you can’t use it along with other values. Properties That Inherit by DefaultĪs mentioned, some properties already inherit their values from their parent element without needing to explicitly tell it so. So, if you aren’t concerned about IE6/7 then you’re safe to use the inherit value on whatever property you want. However, since direction and visibility already inherit by default (see below), this seems somewhat pointless. With two exceptions: Those browsers do support inherit on the direction and visibility properties. The only browsers that don’t support the inherit value are IE6 and IE7 (shocking, I know). And naturally, if you need to reverse the inheritance, you can either remove the property/value pair, or else set it to “normal” instead. Whatever the case, just know that you have the option to use the inherit value. Or maybe you want access to an easy way to change the value via JavaScript or jQuery.

There might also be default styles set by the user agent that you want to override (assuming you’re not already doing so in a CSS reset). Maybe there are other paragraphs with borders set, and so you don’t want those to be affected. But there could be some instances where the inherit method would work better. size by setting a font-size in your projects CSS that targets an icon or. After all, you can just do this:Īnd that would accomplish the same thing. By default, icons inherit the font-size of their parent container which allow.
#Css inherit font size skin
Of course, this seems like just another way to skin the cat, as they say.
#Css inherit font size code
So, if for some strange reason, you wanted all of your paragraphs to inherit the hot pink border of their parent element, then the code above would accomplish this. Here’s an example of how you might do this: If you want, however, you can force a property in a child element to inherit the value for that property from its parent by using the inherit value. When the child is given its own em value, it will compute its value in px based on the computed value of its parent font size. So, a number of properties in the CSS specification are able to naturally pass on their values to child elements. This means that when the child inherits the parents font size it will inherit its parents computed value in pixels ( px ), by default 2em is 32px. This prevents your CSS from looking something like this: This is useful because it prevents needing to define that same property for all children.įor example, the font-size property can be set (as it often is) on the element, and virtually every element that is a child of will inherit that font-size setting. In CSS, there are some properties that are naturally inherited from parent to child. When you set font-size on an element, the element certainly does not inherit font size.
