CSS inheritance

The elements inherit CSS properties from their parent elements that’s all it is.

eg, sa we have an HTML like below

<div>
    <p>Hello world!</p>
</div>

We can just apply a text color to the div tag and it will be applied to the p tag as well since it inherits from the div tag

div{
color: blue;
}

Note: Browsers also have some default styles set for elements, e,g buttons,anchor tags have some default styles from browsers in that case the inheriting will not work and we will have to add the specific styles to the respective tags

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *