Min-width VS max-width media queries for a responsive website

Since for a long time I use the following media queries to make responsive websites

// Large devices (desktops, less than 1200px) @media (max-width: 1199px) { ... } // Medium devices (tablets, less than 992px) @media (max-width: 991px) { ... } // Small devices (landscape phones, less than 768px) @media (max-width: 767px) { ... } // Extra small devices (portrait phones, less than 576px) @media (max-width: 575px) { ... } 

but when I checked bootsrap 4, I noticed that they use the following queries

 /* Small. Above 34em (544px) */ @media screen and (min-width: 34em) { ... } /* Medium. Above 48em (768px) */ @media screen and (min-width: 48em) { ... } /* Large. Above 62em (992px) */ @media screen and (min-width: 62em) { ... } /* Extra large. Above 75em (1200px) */ @media screen and (min-width: 75em) { ... } 

im wondering if i should continue my journey or better follow the bootsrap method and why do they want to start from a small device to a large device?

thanks

+5
source share
2 answers

In its current form, your question is mainly based on opinions.
It would probably be better to ask if anyone knows what the reasons for Bootstrap's approach were, although this question is also primarily based on opinions. But your real chances of getting an answer are much higher than trying to contact Bootstrap authors.
And that’s why I will give you my own considerations , based on a practical approach: I need to do something, I need to quickly, and it must be ready for production.


Regarding the order of @media queries , the only argument for using mobile-first over desktop-first is better for people who have no idea what this means. Therefore, you can always answer your clients / boss when they ask:

- Is this the "mobile first"?
- Of course, we use the latest technology ...

But in the real world, as long as your @media requests apply the correct code to each response interval, you do-it- right .

The only thing you should worry about, in that order, where possible:

  • writing a valid code
  • cross device recording / cross browser code
  • writing supported and easy to read code (for you and other developers)
  • write less code for the same functionality.

As for using em vs px , this is Bootstrap's second attempt at dumping px for em in @media requests. As far as I know, the first attempt was dropped due to lack of support and differences in calculating em for a significant share of mobile browsers at that time. However, a quote is needed here, and I can’t find anything in this discussion, which I remember reading ~ 2 years ago. I'm not even sure if it was around v3 or the prototype v4 that was released at that time. I think it was v4 . In any case, if they decide to use em in v4, em is probably safe to use now.
Edit: Convergence in v4 beta - released just 9 days ago, it looks like you quoted a scss file, later parsed into px requests into the final dist code . Therefore, I assume that the discussion that I remember is still relevant today. In conclusion, I would suggest using em in your CSS @media queries.


The last, but no less important, part of the screen should be taken into account only when you need to take care of how your page looks and how it looks on the screen.

If you need to take care of this, depending on the differences between them, you should estimate the amount of code that you would redefine if all your existing ( screen ) code was applied to print and wrote down all print code from scratch.

If it’s faster at first, don’t add screen to your requests and put @media print . If the latter is faster, wrap the existing code inside @media screen , add screen to your existing requests, like Bootstrap, and put your print code inside another @media print , so it does not affect screen .

Note. . I prefer the first method, as this is a practical approach, easy to test, and usually this leads to a decrease in the amount of code written.

+3
source

It doesn't really matter which option you choose while you choose it. Both do the same thing, but in different approaches. In desktop-first your “base” styles are for desktop / large screens, and you make changes for smaller screens, while in mobile-first you write “basic” styles for mobile / small screens and make changes for large screens. Both are beautiful, and you can use any method that you think makes more sense.

0
source

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


All Articles