Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows screen scale messing up css sizes

Having a weird issue, on Windows 10 in the screen settings on some laptops the default value (the recommended) is 125% so when opening a web page everything is to big because the page was build for 100%

How this can be handled? css? JS? honestly don't know how to approach this

Details:

  • Web app built with React.
  • In 100% everything is scaled correctly
  • From the problematic laptop other websites are scaled correctly (with the settings on 125%)
  • Problematic laptop (don't know if this is relevant) Lenevo yoga 730 15inch

Thanks

like image 517
Blue Bot Avatar asked Apr 18 '18 08:04

Blue Bot


People also ask

How do I fix windows scaling problems?

To work around scaling issues, try the following methods: Log out and in Log out and log back in to the system. This improves how applications and elements are displayed when the monitor configuration changes. Select Display > Change the size of text, apps, and other items, and then adjust the slider for each monitor.

Does Windows scaling affect image quality?

No, it doesn't affect video, that's the point of scaling rather than just changing the resolution.


2 Answers

In CSS you can use (not standard yet):

// refers to 125% @media (-webkit-min-device-pixel-ratio: 1.25) { ... }

and

@media (-webkit-max-device-pixel-ratio: 1.25) { ... }

In Javascript you can use:

window.devicePixelRatio > 1.25 ? doA() : doB()

Reference:

-webkit-device-pixel-ratio - CSS: Cascading Style Sheets | MDN

Window.devicePixelRatio - Web API インターフェイス | MDN

like image 195
xingo Avatar answered Oct 03 '22 04:10

xingo


You might try to add a viewport meta tag in the head section of your index.html:

  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
like image 32
Martin Reiche Avatar answered Oct 03 '22 04:10

Martin Reiche