简体   繁体   English

如何阻止视频标签溢出其容器div。

[英]How to stop a video tag overflowing its container div.

What I need is part of this video to be hidden if its over the containers height. 我需要的是这个视频的一部分,如果它超过容器高度,将被隐藏。

I thought that overflow hidden would be the solution here but somehow it doesn't seem to want to listen. 我认为隐藏的溢出将是解决方案,但不知何故它似乎不想听。

code: 码:

body,
html,
.container,
#video-background {
    height: 100%;
    margin: 0;
    padding: 0;    
}

html {
    overflow-x:hidden;
}

#video-background {
    min-width: 100%;
    min-height: 100%;

    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0; 

    width: 100%;
    height: 100%;    

}

@media (min-aspect-ratio: 16/9) {
  #video-background {
    width: 100%;
    height: auto; /* actually taller than viewport */
   }
}
@media (max-aspect-ratio: 16/9) {
   #video-background {
     width: auto; /* actually wider than viewport */
     height: 100%;
   }
}

Here is my JSfiddle 这是我的JSfiddle

https://jsfiddle.net/dqbq29ru/3/

Also it would be worth finding out or mentioning in comments if you've had problems with the video element in ie9 or up. 如果您在ie9或更高版本中遇到视频元素问题,那么值得在评论中找出或提及。

Many thanks 非常感谢

The answer to this question is that the position absolute on the video tag prevents the use of overflow hidden. 这个问题的答案是视频标签上的绝对位置可以防止使用溢出隐藏。

So I removed this from the video tag as it was not needed in the end and added an overflow hidden to the container. 所以我从视频标签中删除了它,因为它最终不需要,并且在容器中添加了一个隐藏的溢出。

Thanks 谢谢

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

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