Answers for "What's the difference between `.class1.class2` and `.class1 .class2` CSS rule?"

0

What's the difference between `.class1.class2` and `.class1 .class2` CSS rule?

Spacing in between class specifiers means a ascendant -> descendant relationship.

The rule:

.test .heading { font-weight: bold; }

Would apply to the <p> element here:

<span class="test"><p class="heading">Something</p></span>

The lack of space means that the element must have both classes for the rule to apply.

The rule:

.heading.major { color: blue; }

Would apply to the <p> element here:

<p class="heading major">Major heading</p>

..........................................


.class1.class2 

= matches element that has both classes.

.class1 .class2

= matches element with class2 inside element with class1.
Posted by: Guest on March-31-2022

Code answers related to "What's the difference between `.class1.class2` and `.class1 .class2` CSS rule?"

Browse Popular Code Answers by Language