gpt4 book ai didi

css - iPhone 的媒体查询为 iPhone 10 加载 css 而 iPhone 为 8

转载 作者:行者123 更新时间:2023-11-28 01:15:18 26 4
gpt4 key购买 nike

我有一堆为各种 iPhone 编写的 css 媒体查询但是,代码搞砸了。 iPhone 10 的 iPhone 加载 css 是 8,虽然它是 iPhone,但我认为这与最大屏幕尺寸部分相互重叠有关。有什么好的解决方案来解决这个问题吗?例如。为特定手机使用提取屏幕尺寸?

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>test</title>
<meta name='viewport' content='initial-scale=1, viewport-fit=cover'>
<style>
body{
margin:0px;
padding:0px;
background-color:green;
}
header{
height:100vh;
border-bottom:1px solid black;
}
.iphone6,
.iphone6plus,
.iphone10{
display:none;
}
/* ----------- iPhone 6, 6S, 7 and 8 ----------- */
/* Portrait */
@media only screen
and (min-device-width: 375px)
and (max-device-width: 667px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: portrait) {
header{
background-color:red;
height:calc(100vh - 57px);
}
.iphone6,
.iphone6plus,
.iphone10{
display:none;
}
.iphone6{
display:block;
}
}
/* Landscape */
@media only screen
and (min-device-width: 375px)
and (max-device-width: 667px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: landscape) {
header{
background-color:blue;
height:calc(100vh);
}
.iphone6,
.iphone6plus,
.iphone10{
display:none;
}
.iphone6{
display:block;
}

}
/* ----------- iPhone 6+, 7+ and 8+ ----------- */
/* Portrait */
@media only screen
and (min-device-width: 414px)
and (max-device-width: 736px)
and (-webkit-min-device-pixel-ratio: 3)
and (orientation: portrait) {
header{
background-color:pink;
height:calc(100vh - 57px);
}
.iphone6,
.iphone6plus,
.iphone10{
display:none;
}
.iphone6plus{
display:block;
}

}
/* Landscape */
@media only screen
and (min-device-width: 414px)
and (max-device-width: 736px)
and (-webkit-min-device-pixel-ratio: 3)
and (orientation: landscape) {
header{
background-color:orange;
height:calc(100vh);
}
.iphone6,
.iphone6plus,
.iphone10{
display:none;
}
.iphone6plus{
display:block;
}

}

/* ----------- iPhone X ----------- */
/* Portrait */
@media only screen
and (min-device-width: 375px)
and (max-device-width: 812px)
and (-webkit-min-device-pixel-ratio: 3)
and (orientation: portrait) {
header{
background-color:yellow;
height:calc(100vh - 57px);
}
.iphone6,
.iphone6plus,
.iphone10{
display:none;
}
.iphone10{
display:block;
}

}

/* Landscape */
@media only screen
and (min-device-width: 375px)
and (max-device-width: 812px)
and (-webkit-min-device-pixel-ratio: 3)
and (orientation: landscape) {
header{
background-color:olive;
height:calc(100vh);
}
.iphone6,
.iphone6plus,
.iphone10{
display:none;
}
.iphone10{
display:block;
}

}


</style>
</head>

<body>
<header class="iphone6">
iphone 6
</header>
<header class="iphone6plus">
iphone 6 plus
</header>
<header class="iphone10">
iphone 10
</header>
</body>
</html>

最佳答案

iphone 8 和 8+ 的像素比(device-pixel-ratio)是 23,IMO 这就是你的原因正面临这个问题。

要了解有关 device-pixel-ratio 的更多信息,以及有关设备的其他信息,请查看以下链接 https://www.mydevice.io/#compare-devices

/* iPhone 6+, 6s+, 7+, 8+ --------> 3 */
@media only screen .... (-webkit-min-device-pixel-ratio: 3) .... { }

/* iPhone 4, 5, 7, 6, 6s, and 8 --------> 2 */
@media only screen .... (-webkit-min-device-pixel-ratio: 2) .... { }

请根据 device-pixel-ratio 更新您的 css,看看它是否工作正常,希望它能有所帮助:)

关于css - iPhone 的媒体查询为 iPhone 10 加载 css 而 iPhone 为 8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51882905/

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