

I actually like this "feature", because it completely separates the formatting of the headings and the body text.

If you're going to do this, you need to base Heading 1 on "No Style" because Word has 9 levels of Headings, and only accepts 9 generations of styles. This allows you to make radical changes to your document very easily. It's a good idea to set up your heading styles so that Heading 2 is based on Heading 1, Heading 3 is based on Heading 2, and so on. Cascading formatting and headings Base heading styles on the previous heading level style Similarly, if you changed "Body Text" to have 11pt space after each paragraph, then its children and grand-children styles would inherit that formatting, and they would have 11pt space after each paragraph.īut if you then changed style "Table Text" to have 6pt space after each paragraph, the change would affect only "Table Text" and "Table Text Indent". In the document from which Figure 1 was drawn, if you changed style "Body Text" to be Times New Roman, then Body Text, Body Text Indent, Table Text and Table Text Indent would all change to Times New Roman. The point of having styles based on other styles is to make fast changes to your document. The effect will ripple through the whole document instantly. You can then swap between double-spacing and single-spacing by changing the formatting of the parent style. So, by using inheritance we can avoid styling errors.If you want to print a draft of your document double-spaced, set all the styles used in the body of the document to be based on one "parent" stye (like the styles in Figure 1). Otherwise, we need to change it in all places. So, for changing the color, we need to do it in one place. Also, inheritance results in ease of update. So, without inheritance, we need to use a property several times. To summarize, inheritance is an important aspect of styling elements. Output CSS Border Property is Inherited using the inherit Keyword Hence, we get border around element also.


In order to make the border property inheritable, we use border: inherit in the style. Output Example Showing CSS Properties not Inherited by Default However, there is no border for the inside element. Hence, the output shows the border for element. However, the element which is inside doesn’t inherit it by default. The following example shows the use of border property for a div element. So it takes its value from the parent element. Basically, the inherit keyword specifies that the value of this property will be inherited. Output Web Page to Demonstrate Styling Elements Using Inheritance in CSS Using inherit Keywordįor the purpose of inheriting the non-inheritable properties, we use the inherit keyword. Furthermore, the element inside inherits the color property that we have specified for the element. But, since we specify the color for the element, it overrides the inherited property. Hence, the element, and the second element inherit this by default. The following example shows that the color property for the body tag is also applicable to child elements. Examples on Styling Elements Using Inheritance in CSS Similarly, font-size, font-style, font-family, letter-spacing are some of the examples of inherited properties. In contrast, the properties like color are inherited. Furthermore, overflow, z-index, background are some of the examples of non-inheritable properties. For instance, the properties like border, position. However, there are certain properties that can’t be inherited. Hence, there are CSS properties that a child element can inherit from its parent element. In the context of CSS, inheritance means that a child HTML element inherits the styling properties from its parent element. Basically, inheritance allows a child to inherit the properties of their parents. To begin with, let us understand what is inheritance. In this article, I will describe Styling Elements Using Inheritance in CSS.
