Answer the question
In order to leave comments, you need to log in
CSS media queries, why only?
Let me have a few questions about media queries, please:
1. According to the guide "The only operator allows you to include styles for browsers that do not support media queries", for example @media only screen and (color) {/* css-стили */;}
How does it work? I understand that if the browser does not support a media query, then @media
it should not understand the tag, but @media only
if you believe the reference book, the query understands why others, "normal" ones, do not understand? Where is the logic? How so?
2. @media all
- why is the all tag needed? Why not just write @media
? Will not work?
3. @media screen
- what falls under the "screen"? All devices now have a color monitor, from phones to computers (except maybe e-books). What is this tag for and why, arguing with such logic, is it different from all?
4. Forms of requests for several control points:
@media screen and (max-width: 650px) {}
@media screen and (max-width: 1020px) {}
@media screen and (max-width: 320px) {}
Answer the question
In order to leave comments, you need to log in
1-3) @media (max-width: 500px) {} - все
4)
Does a 320 px device fit all three?
Or is it necessary to put media styles strictly in descending order of resolution, so that the bottom one in the code is the one with the smallest resolution?
.elem {
color: red;
@media () {
color: red;
}
}
I'll add Alex Glebov 2, 3
to the answer
. For example, there are also printers and screen readers.
4. If the style matches several requests, then the usual logic applies. Or "overwritten" what is higher in the document, or depending on the specificity of the selectors.
7. I usually do this: if there are few changes for adaptation, then I write the main selector and immediately below it the necessary media. If there are many, then vice versa, the media query and all the selectors that need it are in it.
And most importantly: just test on a simple example with changing the background color depending on the screen size. Write media in one or the other order, see DevTools. Try depending on screen width, viewport, pixel density, aspect ratio, etc. And you will quickly understand.
And also, at the same time, 2 links about viewports of mobile devices at once
https://www.esolutions.se/en-GB/test
viewportsizes.com
(Usually this is the next question, why is a version from 320 displayed on a mobile device with a screen of 1920 pixels)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question