Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inherit CSS class

Tags:

css

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 ?

like image 594
Damir Avatar asked Mar 24 '11 09:03

Damir


People also ask

Can I use inherit CSS?

The inherit keyword can be used for any CSS property, and on any HTML element.

Are classes inherited in HTML?

Can HTML tags inherit the class of a parent/enclosing tag? No. Classes are not inherited.


1 Answers

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.

like image 123
deceze Avatar answered Oct 03 '22 17:10

deceze