Skip to main content
Inspiring
December 6, 2018
Question

(CSS) Refining the targeting of mobile devices

  • December 6, 2018
  • 2 replies
  • 2742 views

So I've been using this great bit of code you guys passed on to me last week to make my site more responsive to mobile.

@media screen and (max-width: 980px) {

.example { font-size: .8em }

}

Only problem is, 980px happens to be the resolution of both my smart phone AND tablet. So when I target devices via resolution only, I cannot differentiate between the two, despite the fact that one is physically 3 times the size of the other and should not be serving the same layout.

Since I want the tablet to display the exact same thing a desktop monitor would -- and simply want to target whatever is physically smaller than the average tablet (so, phones) -- how would I go about refining the code to target 'just phones'?

I'd like phones to serve a very minimalist layout -- just a single zoomed-in text column -- but that looks awful on a tablet. The tablet can comfortably handle the desktop layout, and is much better off with it (I compared both).

PS: I'm aware that 980px just happens to be my own devices' resolution, and your mileage may vary on that front... but after researching mobile resolution standards, it's still one I'm comfortable using as a cut-off point, if I'm forced to pick one.

    This topic has been closed for replies.

    2 replies

    pziecina
    Legend
    December 7, 2018

    I would strongly advise against using your mobile devices as more than a general idea of how a layout will look. Once you do that you are designing for specific settings. The iPhone X and iPad pro have a pixel density of 4x, double that of the iPhone 5, and many devices are starting to use that type of screen.

    Text on all the devices are upscaled from the users settings to have the size appearance of a standard 1x screen, (but a hi-dpi apearance) providing you use the viewport meta tag set to 'device-scale 1'. The only items you have to worry about when designing are images and videos, as these are displayed at the created pixel density.

    For images use the srcset property in html and image-set in css, for video it is best to offer the user the standard 1x video and an option to view a hi-dpi version if they wish.

    Under S.Author
    Inspiring
    December 6, 2018

    I found this potential solution markup.

    Based on what I'm reading there, I can target an iPhone 5S, or I can target a Google Pixel XL, but I can't target both? How would I even begin to combine them when they all have different min/max resolutions?

    Is resolution really the only way to target mobile devices?

    Jon Fritz
    Community Expert
    Community Expert
    December 6, 2018

    Long, long ago, in the before times (10 years ago) we only really had to worry about the latest crop of large 16:9 monitors after years of designing for various sized 4:3 aspect ratio displays. It was a glorious time to be alive, the sun shone, the birds sang and the flowers were always in bloom.

    Then the bad man came, with his black turtleneck and glasses, and he stood on a stage in front of a cheering audience applauding the end of sanity in web design. The dark followed the bad man, everyone wanted to make something that worked the same as the bad man's device, but they all had different thoughts about how big those devices were, the "perfect" aspect ratio and even how many pixels to jam into every square inch. Bedlam ensued. Now there are literally hundreds, if not thousands, of varying device sizes, pixel densities and aspect ratios across more and more devices every day. There's simply no efficient way to detect the individual device and serve appropriate code, so now we have to design our sites to be fluid with certain breakpoints in mind for a handful of specific devices.

    There will always be some cross over where a small tablet gets the phone css or a large phone gets the tablet's, or maybe the refrigerator door sees the desktop css when it was really supposed to see what the dash board of the luxury car uses.

    My point is, crossover is inevitable. You'll drive yourself nuts trying to design for every possible specific device. If there is one you absolutely need to have, combining the other attributes available to css media queries can help. Device-width and pixel density are good ways to help narrow down the css for very specific devices, but even then there will likely be unexpected crossover with some other device that reports to the browser in an unusual way.

    Under S.Author
    Inspiring
    December 6, 2018

    https://forums.adobe.com/people/Jon+Fritz+II  wrote

    Device-width and pixel density are good ways to help narrow down the css for very specific devices, but even then there will likely be unexpected crossover with some other device that reports to the browser in an unusual way.

    As I keep pointing out (probably because as a designer, my thinking isn't as binary as a coder's) I'm not looking for a perfect, full-proof solution. Only the best available compromise known today (after having taken a break from web design for 4-5 years to design more).

    The only method I've been taught to target mobile (just a couple of weeks ago, in this very forum) is screen width. In hindsight, this seems like a very blunt instrument to use when your iPhone and iPad both have 980px as width. Literally the exact same number. Since the screen proportions are different, I'm going to assume their heights differ as well.

    If combining width with height and/or "pixel density" (is that really a thing?) will help me target phones better, even a little, I'd love to know how. It's why this thread exists.

    Could you show me, by modifying the original example below?

    @media screen and (max-width: 980px) {

    .example { font-size: .8em }

    }

    When I change 980px to 979px, both the phone and the tablet receive the desktop layout. When I switch it back to 980px, they both get the minimalist phone layout. I'm trying to send the minimalist layout to the phone only. Desktop to the tablet.

    Doesn't need to be perfect, just better than what I have now (width only).