Answer the question
In order to leave comments, you need to log in
How to force media query styles to override nested Less rules(styles)?
I use such a feature of the Less preprocessor as nesting of styles. Very often, for convenience, I set the styles of nested HTML elements also in a nested form, so that you can understand the structure of the page directly from the style file.
Example:
<div class="event">
<h2 class="event__caption">Игра в футбол</h2>
<p class="event__description">Сегодня состоится товарищеский матч по футболу</p>
</div>
.event {
width: 300px;
height: 100px;
.event__caption {
color: blue;
}
.event__description {
color: green;
}
}
.event__caption { color: red}
Answer the question
In order to leave comments, you need to log in
.event {
width: 300px;
height: 100px;
&__caption {
color: blue;
}
&__description {
color: green;
}
}
@media screen and (max-width: 768px) {
.event {
&__caption {
color: red;
}
}
}
.event {
width: 300px;
height: 100px;
&__caption {
color: blue;
@media screen and (max-width: 768px) {
color: red;
}
}
&__description {
color: green;
}
}
write so that there is no nesting:
.event {
width: 300px;
height: 100px;
&__caption {
color: blue;
}
&__description {
color: green;
}
}
Judging by the code, you are using BEM and messed up something with it (nesting is generally unnecessary here):
BEM:
.event {
width: 300px;
height: 100px;
&__caption {
color: blue;
}
&__description {
color: green;
}
}
@media(max-width: 767px) {
.event__caption { color: red}
}
@media(max-width: 767px) {
.event__caption { color: red !important}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question