Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rewrite background with active class css

I have few div and all are red in color, I use 'red' as the class name. but among the div I want to apply extra class like class="red active" to give selected div extra style.

why this doesn't work

.red{
   background: red;
}

.red .active{
   background: green;
}
like image 413
user3106579 Avatar asked Dec 19 '25 19:12

user3106579


2 Answers

change your css for :

.red.active
like image 70
kevpoccs Avatar answered Dec 22 '25 10:12

kevpoccs


.red .active (with a space between) means an element that has a class active and is the descendant (children, granchildren, etc.) of an element that has a class red. This is called the descendant selector.

You need .red.active (without a space). It means an element that has both a red and active class. This is a multiple class selector.

Recommended read:

Multiple Class / ID and Class Selectors from Chris Coyier

like image 28
kapa Avatar answered Dec 22 '25 09:12

kapa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!