When working with CSS media queries, I am unsure of whether I should program in a mobile-first style, or a desktop-first style.
For example, let’s say I’m given a design that consists of a set of blocks that are side-by-side. On desktop, I’ll stick to spec, but on mobile, given the reduced screen area, two blocks stacked on top of one another would be better.
Which is better, this (desktop-first):
div {
width: 50%;
display: inline-block;
}
@media all and (max-width: 600px) {
width: 100%;
margin: 0 auto;
display: block;
}
or this (mobile first)?
div {
width: 100%;
margin: 0 auto;
display: block;
}
@media all and (min-width: 600px) {
width: 50%;
display: inline-block;
}
WordPress’ latest theme follows the mobile-first method, by using min-width
, but am I correct in assuming that older browsers without media query support would be unable to parse these directives, and load the “mobile” css?
What are the advantages/disadvantages of both?
3
Which is more important to you? Or more accurately, do you think you’re going to draw a larger number of users from mobile than from desktop, or vice versa?
Having a responsive site is excellent, but you need to decide whether you want it mobile first and respond upward, or desktop first and respond downward. There’s no real right or wrong answer to it, it just depends entirely on whether you think you’re going to cater more to one audience than the other.
0