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

标签 html css

我需要的是在视频超过容器高度时隐藏该视频的一部分。

我认为 overflow hidden 将是这里的解决方案,但不知何故它似乎不想听。

代码:

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%;
   }
}

这是我的 JSfiddle

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

如果您在 ie9 或更高版本中遇到视频元素问题,也值得找出或在评论中提及。

非常感谢

最佳答案

这个问题的答案是video标签上的position absolute防止使用overflow hidden。

所以我从视频标签中删除了它,因为最后不需要它,并在容器中添加了一个隐藏的溢出。

谢谢

关于html - 如何阻止视频标签溢出其容器 div。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32141394/

相关文章:

html - 与 z-index 重叠的 div

html - Chrome 截掉了左边的部分字体,firefox 和 IE 显示正常。 Chrome 错误?

html - header 上的未知样式

css - 在 html 和 css 中,如何获得从左向右拉伸(stretch)的 td 背景颜色,而不仅仅是表格宽​​度?

html - CSS 和 Bootstrap : Create a line that connects rows

JQuery SerialScroll 实现

html - 围绕可变高度的 div 画一个完美的圆

html - 你能解释一下为什么在 html 中使用标签 {{ , }} 吗?

html - 横向和纵向的 CSS Bootstrap 设置按钮宽度

html - 单选按钮错误,允许多项选择