简体   繁体   English

iOS上的Safari不适用于媒体查询

[英]Safari on iOS doesn't work with media queries

My problem is that I cannot get media query to work on iPhone 5s iOS 9.3.2 Safari . 我的问题是我无法使媒体查询在iPhone 5s iOS 9.3.2 Safari I have a full screen video on my page what I'd like to change into an image on mobile. 我的页面上有一个全屏视频,我想将其更改为手机图像。 I have followed this tutorial to make it happen. 我已按照本教程进行操作。

I have specified the viewport like this: 我已经指定了这样的viewport

<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

I have included !important tag in every css entry I need to be changed when being 640px, like this: 我在每个css条目中都包含!important标记,在变为640px时需要更改,如下所示:

@media only screen and (max-device-width: 640px) {

 html {
  background: url('image.jpg') no-repeat center center fixed !important;
  background-color: rgba(0, 0, 0, 0) !important;
 }
 #video {
  display: none !important; 
 }
 body{
  background: rgba(0, 0, 0, 0) !important; 
  /*also tried with background:transparent !important*/
 }
}

I decided to use 640px as it is the exact amount of pixels what gets rendered on iPhone 5s according to this source . 我决定使用640px因为根据此消息来源是在iPhone 5s上渲染的确切像素数量。

I have specified that the background should be transparent as it seems to be the only option to work around the default template style. 我指定background应该是transparent因为它似乎是解决默认模板样式的唯一选择。 Meaning when background becomes transparent the background image shows up. 意思是当背景变为透明时,背景图像就会出现。

I have read this and this . 我已经读过这个这个 I have applied the suggested solutions to my problem but none of them worked. 我已将建议的解决方案应用于我的问题,但没有一个起作用。

NOTE: I don't have the Mac machine to test this issue via iPhone's web inspector. 注意:我没有Mac机通过iPhone的Web检查器测试此问题。 Making a VM on Windows seems to be not a one hour job. 在Windows上制作VM似乎不是一个小时的工作。

I have tested my code in Chrome 50.0.2661.102 m (64-bit) , Mozilla 46.0.1 and Edge on Windows Phone everything works fine. 我已经Edge on Windows Phone Chrome 50.0.2661.102 m (64-bit)Mozilla 46.0.1Edge on Windows Phone测试了我的代码,一切正常。

I have tried to work with Safari 5.1.7 (the last version released for Windows), but it seems to be very outdated (as expected). 我曾尝试使用Safari 5.1.7 (Windows的最新版本),但它似乎已经过时了(与预期的一样)。

I have also cleared the cache with Ctrl + Shift + R and tried to use Incognito mode. 我还使用Ctrl + Shift + R清除了缓存,并尝试使用隐身模式。

UPDATE: if I specify the color (for the sake of testing) before the image I will be then able to see the specified color in Safari, but no image: 更新:如果我在图像之前指定了颜色(出于测试目的),那么我将能够在Safari中看到指定的颜色,但是没有图像:

background: green url('image.jpg') no-repeat center center fixed !important;

Any idea how to solve this? 任何想法如何解决这个问题?

While waiting for help I've found a workaround just for my case. 在等待帮助的过程中,我发现了一种针对我的情况的解决方法。 Thanks to @daemeron's answer . 感谢@daemeron的回答

So instead of implementing separate styleheets for different devices it is just possible to hide the annoying Play button on the background by: 因此,除了为不同的设备实现单独的样式表外,还可以通过以下方法在后台隐藏讨厌的“ Play按钮:

*::-webkit-media-controls-start-playback-button {
 display: none!important;
 -webkit-appearance: none
}

This works great on iPhone and Windows 10 mobile. 这在iPhone和Windows 10移动版上效果很好。 Exactly what I was looking for. 正是我想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM