以任何屏幕分辨率制作视频100% [英] Make video fit 100% with any screen resolution

查看:152
本文介绍了以任何屏幕分辨率制作视频100%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下属性的视频,帧宽:1920和帧高:1080。我需要它的宽度和高度为100%,从而填满整个屏幕。而且它也需要响应。到目前为止,我有这样的代码:

I have a video with the following properties, Frame width: 1920 and Frame Height: 1080. I need its width and height to be 100% thus filling up the whole screen. And it needs to be responsive too. So far, I have this code :

<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>

css:

   .videosize {
    position:absolute;
    z-index:-1;
    top:0;
    left:0;
    width:100%; 
    height:100vh;
}

使用上面的代码,它完全符合1680 x 1050屏幕分辨率,但是与其他分辨率一样,它占据了高度的100%,宽度调整会在两侧留下空白。

With the code above it fits perfectly with a 1680 x 1050 screen resolution, however with other resolution, it takes up 100% of the height then the width adjusts leaving white spaces on both sides.

任何想法?感谢。

推荐答案

在这里找到了一个很好的解决方案: http://codepen.io/shshaw/pen/OVGWLG

Found a good solution here: 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%);
}

HTML:

HTML:

<div class="video-container">
  <video>
    <source src="~/Videos/myvideo.mp4" type="video/mp4" />
  </video>
</div>

这篇关于以任何屏幕分辨率制作视频100%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆