我正在设计一个网站,使用自托管的背景视频在100%宽度的容器中。在Chrome和Firefox中运行得非常完美,但在IE(已测试在IE 11)中则失败了。
视频应该横向拉伸以填充容器 - 保持视频比例,然而,IE只是将视频放置在容器中,以垂直方向填充容器所需的大小。
视频应该横向拉伸以填充容器 - 保持视频比例,然而,IE只是将视频放置在容器中,以垂直方向填充容器所需的大小。
/*you can use this css.*/
.fullwidth-video {
position: absolute;
top: 0;
left: 0;
z-index: 1;
min-height: 100%;
min-width: 100%;
-webkit-transform-style: preserve-3d;
}
.fullwidth-video video {
position: absolute;
top: 0;
left: 0;
z-index: 1;
min-height: 100%;
min-width: 100%;
height: auto;
width: 100%;
object-fit: cover;
}
<div class="fullwidth-video">
<video preload="auto" autoplay loop muted="">
<source src="http://sawyerfirm.ignitte.com/wp-content/uploads/2015/12/Girl-Riding-In-Car-8-BW.mp4" type="video/mp4">
<source src="http://sawyerfirm.ignitte.com/wp-content/uploads/2015/12/Girl-Riding-In-Car-8-BW.webm" type="video/webm">
</video>
</div>
This is html code :
<div class="video-frame">
<video class="video-box" autoplay poster="video-back.jpg" id="bgvid" loop>
<source src="sample.webm" type="video/webm">
<source src="sample.mp4" type="video/mp4">
</video>
</div>
This is css code :
.video-frame { position:relative;margin:40px auto;width:100%;}
.video-box { position: fixed; top: 50%; left: 50%; min-width: 100%; min-height: 100%; width: auto; height: auto; z-index: -100; transform: translateX(-50%) translateY(-50%); background: url('video-back.jpg') no-repeat; background-size: cover; transition: 1s opacity;}
已解决
我在IE中遇到了同样的宽度问题:我找到的解决方法是删除应用于<video>
标签上的额外自定义CSS。
这段代码应该可以正常工作:
<!DOCTYPE html>
<html>
<body>
<video width="100%" height="" autoplay>
<source src="http://sawyerfirm.ignitte.com/wp-content/uploads/2015/12/Girl-Riding-In-Car-8-BW.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</body>
</html>
IE不支持object-fit: cover。使用以下库作为IE的后备方案:
.video {
overflow: hidden;
position: relative;
width: 100%;
height: 100%;
/* HTML video tag */
&__player, video {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
object-fit: cover; /* IE not work */
}
}
.video {
overflow: hidden;
position: relative;
width: 100%;
height: 100%;
/* HTML video tag */
&__player, video {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: auto; /* IE change to auto */
}
}
还有HTML代码:
<div class="video">
<video class="video__player" width="400" muted loop>
<source src="XXX" type="video/mp4">
Your browser does not support HTML5 video.
</video>
</div>