css - 设备像素比的媒体查询不起作用

标签 css less media-queries

我在 LESS 中的媒体查询在桌面上运行良好,但在测试 iPad2 或 Samsung Galaxy 4 手机时却不行,它似乎是 device-pixel-ratio 那是在丢东西。我将 min-device-pixel-ratio 降低到 1.5。那也没用。出于某种原因,尽管三星的分辨率为 640x320 而 iPad 的分辨率为 1024x768,但三星和 iPad 都遇到了相同的查询。知道如何更好地分解这些媒体查询吗?

更少的代码:

@screenXS:~"screen and (max-width:479px)";
@screenS:~"screen and (min-width: 480px) and (max-width:639px)";
@screenM:~"screen and (min-width: 640px) and (max-width:767px)";
@screenL:~"screen and (min-width: 768px) and (max-width:1023px)";
@screenXL:~"screen and (min-width: 1024px)";
@dpr:~"(-webkit-min-device-pixel-ratio:2) and (min-device-pixel-ratio:2)";

.myElement {
     @media @screenXS {
          font-size: 10px;
          line-height: 18px;
          @media @dpr {
                color:#f00 !important;
                font-size:20px;
          }
     }
     @media @screenS {
          font-size: 11px;
          line-height: 20px;
          @media @dpr {
                color:#0f0 !important;
                font-size:30px;
          }
     }
     @media @screenM, @screenL {
          font-size: 12px;
          line-height: 21px;
          @media @dpr {
                color:#00f !important;
                font-size:50px;
          }
     }
     @media @screenXL {
          font-size: 14px;
          line-height: 25px;
          @media @dpr {
                color:#ff0 !important;
                font-size:100px;
          }
     }
 }

最佳答案

尝试这样的事情:)

<link href="css/mobile_portrait.css" rel="stylesheet" type="text/css" media="only screen and (min-width: 320px) and (orientation: portrait)">
<link href="css/mobile_landscape.css" rel="stylesheet" type="text/css" media="only screen and (min-width: 480px) and (orientation: landscape)">
<link href="css/tablet.css" rel="stylesheet" type="text/css" media="only screen and (min-width: 769px)">
<link href="css/netbook.css" rel="stylesheet" type="text/css" media="only screen and (min-width: 1024px)">
<link href="css/desktop.css" rel="stylesheet" type="text/css" media="only screen and (min-width: 1224px)">

这只是一个例子!

关于css - 设备像素比的媒体查询不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25811034/

相关文章:

jQuery 条件问题

less - 当你的项目中有多个文件时,如何使用 Grunt 为 LESS 配置 sourceMaps?

html - 媒体查询无法正常工作

javascript - 在不对脚本中的断点宽度进行硬编码的情况下使用 JavaScript 检测动态媒体查询?

css - 更改 ion-checkbox 内复选标记的颜色

javascript - respond.js 将更喜欢媒体查询而不是稍后定义的全局选择器

html - 我的导航栏有什么问题?

javascript - 编辑 "prefers-color-scheme"值以强制使用暗模式

css - CSS 使用文本阴影的效率是否与框阴影一样差?

maven - bootstrap 3.1.0 的 wro4j less 处理失败