I have one base .base{} in my CSS file with couple properties. I want to change only color and other properties to stay same. How to inherit this base class inother classes ?
The inherit keyword can be used for any CSS property, and on any HTML element.
Can HTML tags inherit the class of a parent/enclosing tag? No. Classes are not inherited.
CSS "classes" are not OOP "classes". The inheritance works the other way around.
A DOM element can have many classes, either directly or inherited or otherwise associated, which will all be applied in order, overriding earlier defined properties:
<div class="foo bar">
.foo { color: blue; width: 200px; } .bar { color: red; }
The div will be 200px wide and have the color red.
You override properties of DOM elements with different classes, not properties of CSS classes. CSS "classes" are rulesets, the same way ids or tags can be used as rulesets.
Note that the order in which the classes are applied depends on the precedence and specificity of the selector, which is a complex enough topic in itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With