How To Make Video's Width 100% Or Height 100%
I'm having the same issue as this, but i'm trying to do it on element. I want to make video element sometimes width: 100%, and sometimes height: 100% by aspect ratio
Solution 1:
You almost got it, you missed the sizing of the video tag. object-position could be also handy :
.remoteVideo {
height:100%; /* or is max-height:100%; */
width:100%; /* or is max-width:100%; */
object-fit: contain;
object-position:center;
transform: scale(-1, 1);
}
Possible example to run in full page to test behavior on resize, or version based on max-height
/max-width
100%
https://codepen.io/gc-nomade/pen/bGNzzNj to shrink video if it becomes bigger than the screen .Up to you to choose value for height and width.
body {
margin: 0;
}
.remoteVideo-container {
position: fixed;
left: 0;
top: 0;
z-index: 0;
width: 100vw;
height: 100vh;
text-align: center;
background-color: rgb(45, 48, 53);
}
.remoteVideo {
height: 100%;
width: 100%;
object-fit: contain;
object-position: center;
transform: scale(-1, 1);
}
<div class="remoteVideo-container">
<video class="remoteVideo" autoplay muted poster="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/polina.jpg">
<source src="http://thenewcode.com/assets/videos/polina.webm" type="video/webm" />
<source src="http://thenewcode.com/assets/videos/polina.mp4" type="video/mp4" />
</video>
</div>
Solution 2:
I was able to do it by a small css hack. Set min-width and min-height to 100% and then height and width to auto to prevent from stretching or zooming in the video. And a bit more to center the video.
.remoteVideo {
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
Post a Comment for "How To Make Video's Width 100% Or Height 100%"