-2

I found on the web that I can style the HTML with multiple classes using the syntax:

.class1.class2 {
    /* style here */
}

And I have a big project with css files with the syntax:

.class1 .class2 {
    /* style here */
}

(there's a space between the classes)

Looks like, for me, that this code with space between the classes names are doing nothing... Maybe is an alternative to comment. Is it?

The Student
  • 27,520
  • 68
  • 161
  • 264

1 Answers1

1

Yes. In CSS selectors, unlike Javascript for example, whitespace is not ignored.

.A.B Will select elements that have both class A and class B.

.A .B Will select any .B class elements that are inside .A class elements.

Example:

<A class="A B">
    <B class="A"></B>
    <B class="B"></B>
</A>

In this case:

.A.B Will return only the <A class="A B"> element.

.A .B Will return <B class="B">, as it is a B class element inside an A class element.

Sources:

Community
  • 1
  • 1
Selfish
  • 6,023
  • 4
  • 44
  • 63