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 ?
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.
A space is a descendent selector, i.e. "Matches the right hand side only if one of its ancestors matches the left hand side".
See the descendant section of Selectutorial
.class
works because any element that matches the rule "A div that is a member of the class 'class'" will also match the rule "A member of the class 'class'", it is just less specific.
div.class
refers to all divs with the class 'class.' .class div
, on the other hand, refers to all divs that are children of the element with the class 'class.' .class
refers to all elements with the class 'class.'
Although the dot, fullstop, period, . , is used instead.