【问题标题】:Media query doesn't update in rotating for iphone 4 and iphone 5siphone 4 和 iphone 5s 的媒体查询在轮换时不会更新
【发布时间】:2015-05-18 20:09:42
【问题描述】:

当我在纵向和横向之间旋转 iPhone 4 和 iPhone 5s 时,媒体查询中的 CSS 不会更新。

由于我在媒体查询 css 中使用视口度量 vw 和 vh,我希望它们在纵向和横向之间旋转时重新应用 - 它们在除 iPhone 4 和 iPhone 5s 之外的所有手机中都可以正常工作。当我从纵向旋转到横向时,纵向的宽度也保持在横向。

我不明白为什么只有 iPhone 4 和 iPhone 5s 有这个问题。我的 css 一定有问题吗?

[编辑]代码片段如下:

@media only screen 
and (min-device-width : 320px) and (max-device-width : 640px)
{
...
.products .product .info
{
    width: 80vw;
    margin: 0 0 0 0;
}
...
}

当我在 iPhone 4 中从纵向旋转到横向时,80vw 保持相同的宽度。如果我以横向刷新页面,80vw 的物理宽度不会改变。我可以得到任何帮助吗?

【问题讨论】:

  • 请提供一些代码。媒体查询断点。
  • Petroff,我刚刚添加了一些示例代码和一个关于它们的问题。

标签: css media-queries viewport iphone-4


【解决方案1】:

这里有一些来自CSS-Tricks的好例子

/* iPhone 4 (landscape) ----------- */
@media only screen and (min-device-width : 320px) and (max-device-width : 480px) and (orientation : landscape) and (-webkit-min-device-pixel-ratio : 2) {
/* Styles */
}

/* iPhone 4 (portrait) ----------- */
@media only screen and (min-device-width : 320px) and (max-device-width : 480px) and (orientation : portrait) and (-webkit-min-device-pixel-ratio : 2) {
/* Styles */
}

/* iPhone 5 (landscape) ----------- */
@media only screen and (min-device-width: 320px) and (max-device-height: 568px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}

/* iPhone 5 (portrait) ----------- */
@media only screen and (min-device-width: 320px) and (max-device-height: 568px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}

/* iPhone 6 (landscape) ----------- */
@media only screen and (min-device-width: 375px) and (max-device-height: 667px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}

/* iPhone 6 (portrait) ----------- */
@media only screen and (min-device-width: 375px) and (max-device-height: 667px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}

/* iPhone 6+ (landscape) ----------- */
@media only screen and (min-device-width: 414px) and (max-device-height: 736px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}

/* iPhone 6+ (portrait) ----------- */
@media only screen and (min-device-width: 414px) and (max-device-height: 736px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}

【讨论】:

  • 谢谢,但是,我的问题是在 iPhone 4 中旋转时 css 不适用。
猜你喜欢
  • 1970-01-01
  • 2015-07-15
  • 2018-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-21
  • 2017-03-15
相关资源
最近更新 更多