A
A
Alexey Romankov2022-03-21 18:31:17
css
Alexey Romankov, 2022-03-21 18:31:17

Why doesn't it work with &?

In general, the problem was solved by itself, but I do not understand the reason for its occurrence.
Here is the code:

<div class="block">
         <div class="block__1">
            .block__1
         </div>
         <div class="block__2">
            .block__2
         </div>
         <div class="block__3">
            .block__3
         </div>
      </div>


here is the SCSS:
.block {
   div{
      line-height: 50px;
      font-size: 18px;
      font-weight: 700;
      text-align: center;
      color: #fff;
   }
   border: 5px solid red;
   max-width: 800px;
   margin: 0px auto;
   height: 800px;
   &__1 {
      background-color: green;
   }

   .block__2 {
      background-color: yellow;
      color: black;
   }

   &__3 {
      background-color: blue;
   }
}


Why when specifying the second block in SCSS through &:
.block {
   div{
      line-height: 50px;
      font-size: 18px;
      font-weight: 700;
      text-align: center;
      color: #fff;
   }
   border: 5px solid red;
   max-width: 800px;
   margin: 0px auto;
   height: 800px;
   &__1 {
      background-color: green;
   }

   &__2 {
      background-color: yellow;
      color: black;
   }

   &__3 {
      background-color: blue;
   }
}


does the text color stay white?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
iBird Rose, 2022-03-21
@Yeashua

and in the inspector to look first before writing here is not fate?
62389afb4ffa5939127052.jpeg
your styles are messed up

R
Rsa97, 2022-03-21
@Rsa97

.block {
    .block__2 {
        ...
    }
}
This is a selector.block .block__2
.block {
    &__2 {
        ....
    }
}
This is a selector .block__2
These selectors can refer to the same elements, but have different specificities .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question