是否有可能在绝对定位的 <video>
元素中有一个 HTML5 调整到窗口的宽度和高度,这样就不会裁剪任何东西?我见过的很多解决方案似乎都依赖于 <iframe>
标签,我没有,或者只根据宽度调整大小(我已经可以做到)。
基本上我正在寻找一种方法来确保视频尽可能大,但如果调整窗口大小也不会被裁剪——即使在 IE9 中也是如此。 (注意:我的视频必须保持其比例——所以如果有黑条也没关系。)
到目前为止,这是我尝试过的。
/*CSS*/
#player-overlay {
position: absolute;
display: none;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #000
z-index:999;
}
<!--HTML-->
<div id="player-overlay">
<video width="100%" video="100%" style="width:100%, height:100%">
<source src="../static/video/10s.mp4" />
<source src="../static/video/10s.webm" type='video/webm; codecs="vp8, vorbis"' />
<source src="../static/video/10s.ogv" type='video/ogg; codecs="theora, vorbis"' />
</video>
</div>
在我看来,我将尝试编写一个 JS 解决方案。
原文由 Chuck Le Butt 发布,翻译遵循 CC BY-SA 4.0 许可协议
在
<video>
元素上使用width
和max-height
:http://jsfiddle.net/fHG69/
此外,您在
background-color
之后缺少分号。 When absolutely positioning an element to fill the screen, I prefer to settop
,bottom
,left
, andright
instead of settingheight
和width
。