【发布时间】:2026-02-08 11:25:02
【问题描述】:
这里有很多关于如何制作背景 HTML5 视频的问题,但我对此没有任何问题,它工作正常(除了一个小问题,它只会播放音频而不是视频,直到我在页面上选择某些内容或调整它的大小,有关该问题,请参见此处:Chrome Only Plays Audio Until Resize
我想要做的是让视频适合背景,这样它就不会出现任何信箱(当纵横比不匹配时,上方/下方或两侧的线条)。也就是当高度小于比例时适合宽度,当宽度小于比例时适合高度。
这会切断一些视频,但没关系,我只是想摆脱信箱。有没有办法只用 CSS 来做到这一点,如果不是什么 javascript/jQuery/我需要使用什么?
到目前为止我的代码:
#mashvid {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: auto;
min-width: 100%;
z-index: -5;
}
<video preload id="mashvid" poster="images/mashvid_poster.png">
<source src="http://www.mashwork.com/testsite/video/mashwork1080.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>
<source src="http://www.mashwork.com/testsite/video/mashwork1080.ogv" type='video/ogg; codecs="theora, vorbis"'>
<source src="http://www.mashwork.com/testsite/video/mashwork1080.webm" type='video/webm; codecs="vp8, vorbis"'>
Your browser does not support the video tag.
</video>
【问题讨论】:
标签: html fullscreen html5-video