CSS selector syntax question

I have a question about CSS selector syntax.

What is the difference between the following two CSS selectors?

.myclass1 .myclass2 {
    color: black;
}

.myclass1.myclass2 {
    color: black;
}

Are they the same?

Thank.

+3
source share
2 answers

.myclass1 .myclass2: select the element that has the class "myclass2" inside another element of the class "myclass1";

.myclass1.myclass2: Select an item that has both classes.

+7
source

.myclass1 .myclass2 will match the div's internal

<div class="myclass1">
    <div class="myclass2"></div>
</div>

.myclass1.myclass2 will match

<div class="myclass1 myclass2"></div>
+5
source

Source: https://habr.com/ru/post/1779462/


All Articles