Qwe*_*rty 23 css asp.net-mvc html5 twitter-bootstrap
我有一个具有以下属性的视频,帧宽:1920和帧高:1080.我需要它的宽度和高度为100%,从而填满整个屏幕.它也需要响应.到目前为止,我有这个代码:
<video class="hidden-xs hidden-sm hidden-md hidden-custom videosize embed-responsive-item" autoplay="autoplay" loop="loop">
<source src="~/Videos/myvideo.mp4" type="video/mp4" />
</video>
Run Code Online (Sandbox Code Playgroud)
CSS:
.videosize {
position:absolute;
z-index:-1;
top:0;
left:0;
width:100%;
height:100vh;
}
Run Code Online (Sandbox Code Playgroud)
使用上面的代码,它完全符合1680 x 1050的屏幕分辨率,但是对于其他分辨率,它占据了高度的100%然后宽度调整,在两侧留下白色空间.
任何的想法 ?谢谢.
小智 45
在这里找到了一个很好的解决方案:http://codepen.io/shshaw/pen/OVGWLG
所以你的CSS将是:
.video-container {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
height: 100%;
overflow: hidden;
}
.video-container video {
/* Make video to at least 100% wide and tall */
min-width: 100%;
min-height: 100%;
/* Setting width & height to auto prevents the browser from stretching or squishing the video */
width: auto;
height: auto;
/* Center the video */
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<div class="video-container">
<video>
<source src="~/Videos/myvideo.mp4" type="video/mp4" />
</video>
</div>
Run Code Online (Sandbox Code Playgroud)
Dav*_*vid 10
您现在可以使用object-fit属性.此属性专门用于管理响应大小<img>和<video>元素.现在所有现代浏览器都支持它.
.videosize {
position: absolute;
z-index: -1;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
}
Run Code Online (Sandbox Code Playgroud)
小智 5
.video-container {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
height: 100%;
overflow: hidden;
object-fit: fill;
}
.video-container video {
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
Run Code Online (Sandbox Code Playgroud)
这对我有用。