最小宽度媒体查询在 ipad 上不起作用?

发布于 2024-12-09 05:58:06 字数 350 浏览 0 评论 0原文

为什么在横向模式下的 iPad 上无法拾取以下媒体查询?

@media all and (min-device-width: 1000px) {
    css here
}

或者

@media all and (min-width: 1000px) {
    css here
}

我希望这个 css 能够针对任何宽度为 1000px 或以上的浏览器,而不仅仅是 ipad。因此,如果可能的话,我宁愿使用第二个选项 min-width 而不是 min-device-width 。两个版本都可以在我的电脑上使用 Firefox 正常运行。 谢谢

Why isnt the following media query being picked up on iPads in landscape mode?

@media all and (min-device-width: 1000px) {
    css here
}

Or

@media all and (min-width: 1000px) {
    css here
}

I want this css to target any browser which is 1000px wide or over, not just ipads. For this reason id rather work with the 2nd option of min-width not min-device-width if possible. Both versions work fine with firefox on my PC.
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

木落 2024-12-16 05:58:07

来自 http://perishablepress .com/press/2010/10/20/target-iphone-and-ipad-with-css3-media-queries/

/* iPad [portrait + landscape] */
@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {
    .selector-01 { margin: 10px; }
    .selector-02 { margin: 10px; }
    .selector-03 { margin: 10px; }
}

看起来可能需要 screen 属性。

From http://perishablepress.com/press/2010/10/20/target-iphone-and-ipad-with-css3-media-queries/

/* iPad [portrait + landscape] */
@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {
    .selector-01 { margin: 10px; }
    .selector-02 { margin: 10px; }
    .selector-03 { margin: 10px; }
}

It looks like the screen attribute may be required.

献世佛 2024-12-16 05:58:07

如果发现这对新 iPad 非常有效

@media screen and (orientation:landscape) and (min-device-height:1000px) and (-webkit-min-device-pixel-ratio : 2) {
    * {
        color:white;
        background-color:red;
    }
}

If found this works great for the new iPad

@media screen and (orientation:landscape) and (min-device-height:1000px) and (-webkit-min-device-pixel-ratio : 2) {
    * {
        color:white;
        background-color:red;
    }
}
我三岁 2024-12-16 05:58:07

根据记录,我不确定为什么

@media (min-width: 1000px) {

 /* css here */

}  

不适合你。自从这个问题首次发布以来,iPad 可能发生了一些变化吗?

这是一个有效的示例:
实时视图:http://fiddle.jshell.net/panchroma/Bn4ah/show/
编辑视图: http://fiddle.jshell.net/panchroma/Bn4ah/

另外请确保包含

<meta name="viewport" content="width=device-width, initial-scale=1.0">  

在页面的头部。

For the record, I'm not sure why

@media (min-width: 1000px) {

 /* css here */

}  

didn't work for you. Possibly something changed with the iPad since this question was first posted?

Here's a working example:
live view: http://fiddle.jshell.net/panchroma/Bn4ah/show/
edit view: http://fiddle.jshell.net/panchroma/Bn4ah/

Also be sure to include

<meta name="viewport" content="width=device-width, initial-scale=1.0">  

in the head of your page.

后来的我们 2024-12-16 05:58:07

我试图使用像这样的简单媒体查询:
@media only 屏幕和(最小宽度:768px)
{此处为CSS}
但我不会在我正在测试的 iPad pro 10.5' 上触发,我将其增加到 900px(对于纵向)并且它工作得很好,我认为由于您需要补偿视网膜显示屏,它可能在旧设备上工作得很好iPad 非视网膜显示屏。

I was trying to use a simple media query like this:
@media only screen and (min-width : 768px)
{css here}
but I wouldn't trigger on an iPad pro 10.5' I was testing on, I increase it to 900px (for portrait) and it worked just fine, I think because of the retina display you need to compensate, it may work fine on old iPads non-retina.

且行且努力 2024-12-16 05:58:07

在尝试为平板电脑编写媒体查询时,我实际上遇到了 iPad 少报其尺寸的问题。当我尝试使用 @media screen 和 ( min-width: 768px ) 时,我的样式被应用到其他平板电脑设备,但被 iPad 忽略。我开始在开发人员工具中尝试响应式设备模型,并偶然发现了该解决方案。由于某种原因,当我将屏幕尺寸缩小到 760px 时,我的样式将会应用。因此,我编辑了媒体查询以读取 @media screen 和 ( min-width: 760px ) ,一切都开始按预期工作。

Trying to write a media query for tablet, I actually encountered the problem of the iPad underreporting its dimensions. When I tried to use @media screen and ( min-width: 768px ), my styles were being applied to other tablet devices, but ignored by the iPad. I started playing around with the Responsive device model in developer tools, and I stumbled onto the solution. For some reason, my styles would apply when I sized the screen down to 760px. So, I edited the media query to read @media screen and ( min-width: 760px ) and everything started working as expected.

給妳壹絲溫柔 2024-12-16 05:58:06

iPad 始终报告其宽度为 768px,高度为 1024px,因此您必须了解它如何随 orientation 旋转并使用 min-device-height:1000px像这样:

     /* This will apply to all screens with a width 999px and smaller */
* {
     color:green;
     background-color:black;
}

     /*
       This will apply to all screens larger then 1000px wide 
       including landscape ipad but not portrait ipad. 
      */
@media (orientation:landscape) and (min-device-height:1000px),
       all and (min-width:1000px) {
    * {
        color:white;
        background-color:red;
    }
}

结果:

  • iPad
    • 肖像       - 绿色文本 - 黑色背景
    • 风景 - 白色文字  - 红色背景
  • iPhone
    • 肖像       - 绿色文本 - 黑色背景
    • 横向 - 绿色文本 - 黑色背景
  • 计算机(分辨率)
    • 1680x1050 - 白色文本- 红色背景
    • 800x600     -绿色文本-黑色背景

使用chrome和firefox(还有人用IE吗?)

参考文献:
w3 媒体查询
Safari CSS参考
优化网页内容

The iPad is always reporting its width as 768px and its height as 1024px, so you have to find out how it is rotated with orientation and use min-device-height:1000px like so:

     /* This will apply to all screens with a width 999px and smaller */
* {
     color:green;
     background-color:black;
}

     /*
       This will apply to all screens larger then 1000px wide 
       including landscape ipad but not portrait ipad. 
      */
@media (orientation:landscape) and (min-device-height:1000px),
       all and (min-width:1000px) {
    * {
        color:white;
        background-color:red;
    }
}

Results:

  • iPad
    • Portrait       - green text - black background
    • Landscape - white text  - red background
  • iPhone
    • Portrait       - green text - black background
    • Landscape - green text - black background
  • Computer (resolution)
    • 1680x1050 - white text  - red background
    • 800x600     - green text - black background

Using chrome & firefox (does anyone even use IE anymore?)

References:
w3 media queries
Safari CSS Reference
Optimizing Web Content

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文