Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between 'div .class', '.class' and '.class div'

Tags:

css

I have a div like : <div class='class'>

I notice that div.class handles this style, while .class div does not. Moreover, .class handles the style as well.

Why is that ?

like image 698
Spyros Avatar asked Nov 27 '22 18:11

Spyros


1 Answers

I notice that div.class handles this style, while .class div does not.

div.class looks for a div with the class class present.

.class div looks for a div that is a descendent of an element with the class class.

Your element is a div with the class class, hence the selector does not select it.

Moreover, .class handles the style as well.

.class will select any element with that class, including any div elements.

like image 131
alex Avatar answered Dec 09 '22 18:12

alex