简体   繁体   English

我可以在桌面以外的所有内容上隐藏html5视频标记吗?

[英]Can I hide html5 video tag on everything but desktops?

Is there a way to do that? 有没有办法做到这一点? I don't want the video showing up on tablets or phones. 我不希望视频出现在平板电脑或手机上。

Use CSS media queries like this: 使用CSS媒体查询,如下所示:

@media screen and (max-width: 680px)
{
    .video { display : none; }
}

This will hide the class .video for all screens up to 680px wide 这将隐藏所有屏幕最大680px的class .video

Edit: You can of course also do this the other way around, and set .video to display: none by default, and then use min-width inside a media query to actually show it from a certain width. 编辑:当然,您也可以采用其他方法,并将.video设置为display: none默认情况下display: none ,然后在媒体查询中使用min-width实际从某个宽度显示它。

  1. detect width with css media queries or JS 使用CSS媒体查询或JS检测宽度
  2. android tablets have "mobile" in their browser user agent , ios is easy to detect. android平板电脑的浏览器用户代理中包含“ mobile”,而ios易于检测。
  3. detect support for the video tag with modernizr . 使用modernizr检测对视频标签的支持。

Yes, with media queries: 是的,使用媒体查询:

<div id="video">
  //Video here
</div>

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

    #video {
      visibility: hidden;
    }

}

This will hide the div with the ID of "video" for screensizes smaller than 500px (or whatever pixel width you determine). 对于小于500像素(或您确定的任何像素宽度)的屏幕尺寸,这将隐藏ID为“视频”的div。

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

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