我们可以使用屏幕分辨率而不是视口来应用 CSS 吗?

互联网 行业动态 更新时间:2024-06-13 00:19:06

onk*_*kar 5

为了区分缩放比例的变化,我们需要查看像素密度。分辨率媒体功能可用于:

/* used just for the demo*/
* {
  margin: 0;
  padding: 0;
}


/* your normal device specific media queries 
    @media (min-width: 1200px) {
      ...
    }
    @media (min-width: 1400px) {
      ...
    } */


/***********************/

.nonscaling {
  transform-origin: 0 0;
  background-color: wheat;
  width: fit-content;
}


/* scaling media queries */


/* 1. scale and layout setting at 100% */
@media (resolution: 1dppx) {
  .scale::after {
    content: '100%';
  }
}


/* 2. scale and layout setting at 125% */
@media (resolution: 1.25dppx) {
  .scale::after {
    content: '125%';
  }
  .nonscaling {
    /* offset the scaling */
    /* factor = 100/125 percent */
    transform: scale(0.80);
  }
}


/* 3. scale and layout setting at 150% */
@media (resolution: 1.5dppx) {
  .scale::after {
    content: '150%';
  }
  .nonscaling {
    transform: scale(0.6666);
  }
}


/* 4. scale and layout setting at 175% */
@media (resolution: 1.75dppx) {
  .scale::after {
    content: '175%';
  }
  .nonscaling {
    transform: scale(0.5714);
  }
}
<div class="nonscaling">I will not scale! Period.</div>
<div class="scale">You've scaled: </div>

在 Windows 设置中,将设置更改Scale and layout为 100%、125%、150% 或 175%。并在此处查看效果。
在上面的代码片段中,我们使用了dppxunit ,您可以使用其他 units。为了补偿我们使用transform: scale(..)特征的缩放元素。您可以使用缩放,但 Firfox不支持它。

注意:您可以应用transform:scale(..)到整个 body 标签以使用一条规则处理所有内容。
此外,您可以尝试组合最小分辨率、最大分辨率和最小宽度、最大宽度,例如@media (min-width:1200px) and (resolution: 1dppx).

更多推荐

可以使用,而不是,屏幕分辨率,CSS,视口来

本文发布于:2023-04-20 20:49:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/hyzx/99b11e5f62d993479b6515cfa7036ac8.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可以使用   而不是   屏幕分辨率   CSS   视口来

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!