0

I'm trying to change image size with css styles for different devices. The common way of doing so is to use media queries to check device resolution and then switch to corresponding style.

However despite the big resolution in pixels on modile devices, the real size of mobile screens is smaller then desktop screens, and so the image as well. Because of that on desktops image looks too big and blurry and on mobile devices too small, even with right resizing that depend on resolution. So my idea is to check what that device really is and adjust size depending on that and not on screen resolution.

On desktops I want to set max-width of the image to 840px, so it would never be too big (the height correspond to width) and on mobile devices don't set up max-width at all, so image can be as big, as all the other resize-logic allow.

The best I have so far is cheking for orientation - portrait always mean mobile. But in landscape orientation I still can't figure it out how to resize right for different types of devices.

Ex-Deo
  • 11
  • 2
    "check device resolution and then switch to corresponding style." - I suggest you do further reading about how media-queries actually work. A CSS `px` is **not** the same as a physical screen pixel - it's already invariant w.r.t. physical display DPI _because_ of the reasons you've pointed out. – Dai Jul 21 '21 at 08:24
  • In that case what should I use if I want to set up max-width as same as original image width? I was sure that default meaning for px would be as same as for image resolution as well. – Ex-Deo Jul 21 '21 at 08:37
  • Does this answer your question? [Media Queries: How to target desktop, tablet, and mobile?](https://stackoverflow.com/questions/6370690/media-queries-how-to-target-desktop-tablet-and-mobile) – The Anonymous Koder Jul 21 '21 at 10:28

0 Answers0