我正在设计一个在100%宽度容器中使用自托管背景视频的网站。在Chrome和Firefox中完美运行但在IE中失败(在IE 11中测试)。
视频应该在宽度方向上拉伸以填充容器 - 保持视频比例,但是,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;
}
这里的HTML代码......
<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上将高度设置为自动视频。
在其他浏览器上:
.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 */
}
}
在IE上:
.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>
object-fit:IE不支持封面。使用以下库,充当IE的后备: