简体   繁体   English

Windows 屏幕比例弄乱了 css 大小

[英]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%有一个奇怪的问题,在某些笔记本电脑的屏幕设置中的 Windows 10 上,默认值(推荐)是 125% 所以当打开网页时一切都很大,因为页面是为 100% 构建的

How this can be handled?如何处理? css? css? JS? JS? honestly don't know how to approach this老实说不知道如何处理这个

Details:详情:

  • Web app built with React.使用 React 构建的 Web 应用程序。
  • In 100% everything is scaled correctly 100% 一切都正确缩放
  • From the problematic laptop other websites are scaled correctly (with the settings on 125%)从有问题的笔记本电脑上正确缩放其他网站(设置为 125%)
  • Problematic laptop (don't know if this is relevant) Lenevo yoga 730 15inch有问题的笔记本电脑(不知道是否相关) Lenevo yoga 730 15inch

Thanks谢谢

In CSS you can use (not standard yet):在 CSS 中你可以使用(还不是标准的):

// 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:在 Javascript 中,您可以使用:

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

Reference:参考:

-webkit-device-pixel-ratio - CSS: Cascading Style Sheets | -webkit-device-pixel-ratio - CSS:层叠样式表 | MDN MDN

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

您可以尝试在 index.html 的 head 部分添加一个视口元标记:

  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

You could use CSS resolution for this您可以为此使用 CSS 分辨率

/* Exact resolution */
@media (resolution: 150dpi) {
  p {
    color: red;
  }
}

/* Minimum resolution */
@media (min-resolution: 72dpi) {
  p {
    text-decoration: underline;
  }
}

/* Maximum resolution */
@media (max-resolution: 300dpi) {
  p {
    background: yellow;
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM