Answer the question
In order to leave comments, you need to log in
How to include styles for the mobile version of the site?
There is a site that is written for desktops, now you need to make it adaptive for mobile devices.
I do like this:
@media screen and (max-width: 800px) {
* {
display: block; /* просто проверка */
}
}
!important
. I understand that this happens because the styles I write with the media query do not "cover" the styles of the desktop version, but are displayed along with them. Answer the question
In order to leave comments, you need to log in
A smarter approach is mobile-first .
All media are written by min-width starting from the smallest.
It doesn't matter if you only have a desktop layout. Tighten up and count.
The share of mobile traffic is higher than desktop traffic.
If still desktop-first, then by max-width in reverse order, starting with a larger width.
The media themselves are written at the bottom of the css file unless you are blocking the files.
You may find it more convenient to write media directly below the selector.
Then, when building, it would be nice to run the file through a plugin that groups media conditions and puts them at the bottom of the file.
If you need !important, it's likely that the body is nesting too many selectors. And then write a simple selector or a selector with less weight.
Read about the specificity of selectors and/or simplify your code.
The rest is on a specific example.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question