iPhone媒体查询无法在Safari中运行,在Chrome中可以

时间:2018-09-26 00:57:23

标签: css3 ionic-framework safari media-queries mobile-safari

我正在使用以下@media查询在iPhone上的人像/风景。在响应式/ iPhone模式下,它们在Chrome中可以正常工作,但在Safari中则不能。我在做什么错了?

@media only screen 
  and (max-device-width: 414px) 
    and (max-device-height: 812px) 
  and (orientation: portrait)
  and (-webkit-min-device-pixel-ratio: 2) {

  .mq-landscape {
    display:none;
  }
}

@media only screen 
  and (max-device-width: 812px) 
    and (max-device-height: 414px) 
  and (orientation: landscape)
  and (-webkit-min-device-pixel-ratio: 2) {
  .mq-portrait {
    display:none;
  }
}

这是一个堆栈闪电链接:

参考:https://forum.ionicframework.com/t/v4-iphone-media-queries-not-working-in-safari-simulator-ok-in-chrom/142730/2

1 个答案:

答案 0 :(得分:0)

使用max-width代替max-device-width

查看此答案:Safari Responsive Design Mode CSS media query 'device' not applied

这是Safari的更正/工作示例:

@media only screen 
  and (max-width: 414px) 
    and (max-height: 812px) 
  and (orientation: portrait)
  and (-webkit-min-device-pixel-ratio: 2) {

  .mq-landscape {
    display:none;
  }
}