gpt4 book ai didi

android - 用于区分 Google Pixel 1/2、Google Pixel XL 和 Google Pixel 2 XL 的媒体查询

转载 作者:行者123 更新时间:2023-11-29 14:12:31 25 4
gpt4 key购买 nike

我正在编写一个 cordova 应用程序,需要隔离这些谷歌手机以调整样式

鉴于此:

enter image description here

我很难区分任何一款 Google Pixel 手机。

@media only screen and (min-width: 411px) and (max-width: 731px) {
.myDiv{ background-color: blue; }
}

这会在所有 Pixel 上触发——包括模拟器和物理设备

@media only screen and (min-width: 411px) and (-webkit-device-pixel-ratio: 3) {
.myDiv{ background-color: blue; }
}

这根本不会触发任何像素手机 - 3 或 4 像素比例无关紧要

@media screen and (device-width: 411px) and (device-height: 731px) and (orientation: portrait) and (-webkit-device-pixel-ratio: 2.6){
.myDiv{ background-color: blue;
}

这也不会在任何像素手机上触发

我什至很难找到一个用于隔离 Google Pixel 2 XL 的媒体查询 - 似乎没有发布任何内容 - 但手机已经有一段时间了?

有没有人对此有任何好运?

最佳答案

您可以获得设备的宽度、高度和 pixel aspect ratio使用 Javascript。

输出设备信息函数

function OutputDeviceInformation() {
let deviceWidth = window.screen.width;
let deviceHeight = window.screen.height;
let devicePixelAspectRation = window.devicePixelRatio;

console.log('Width: ' + deviceWidth);
console.log('Height: ' + deviceHeight);
console.log('Pixel Aspect Ratio: ' + devicePixelAspectRatio);
}

Google Pixel 2 XL 输出:

宽度:412px

高度:823px

像素纵横比:3.5

针对 Google Pixel 2 XL 的媒体查询

/* Portrait */
@media screen
and (device-width: 412px)
and (device-height: 823px)
and (-webkit-device-pixel-ratio: 3.5)
and (orientation: portrait) {

}

/* Landscape */
@media screen
and (device-width: 412px)
and (device-height: 823px)
and (-webkit-device-pixel-ratio: 3.5)
and (orientation: landscape) {

}

/* Target Portrait and Landscape */
@media screen
and (device-width: 412px)
and (device-height: 823px)
and (-webkit-device-pixel-ratio: 3.5)
and (orientation: landscape) {

}

关于android - 用于区分 Google Pixel 1/2、Google Pixel XL 和 Google Pixel 2 XL 的媒体查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49078882/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com