I have a background video, (code below) that is way too tall. how can I cut off the edges dynamically so that the video is only the height of the viewport? Javascript/jQuery is fine.
here’s the code:
<div class="row parent-container">
<div class="w100 video-container">
<video autoplay loop muted width="100%">
<source id="mp4" src="premiere/IMG_1956.mp4" type="video/mp4">
<source id="jpg" src="images/IMG_0386.JPG" type="photo/jpg">
</video>
</div>
<div class="welcome">
<h1>
We strive to use all natural, organic, and local ingredients wherever we can.<br>
We hope to leave the smallest ecological footprint possible.<br>
As the science of sustainability advances, we will continue to move in the same direction.<br>
Join us!
</h1>
</div>
</div>
so I got it to be the right height, but now the rest of the content is ignoring the section’s existence. Here’s the code:
<div class="row parent-container">
<div class="w100 video-container">
<video autoplay poster="images/IMG_0386.JPG" loop muted width="100%" id="bkvid">
<source id="mp4" src="premiere/IMG_1956.mp4" type="video/mp4">
</video>
</div>
<div class="welcome">
<h1>
We strive to use all natural, organic, and local ingredients wherever we can.<br>
We hope to leave the smallest ecological footprint possible.<br>
As the science of sustainability advances, we will continue to move in the same direction.<br>
Join us!
</h1>
</div>
</div>
this is perfect, thanks! Just to clarify, is it the min-height: 100vh; style on the text and the overflow: hidden; on the parent container that is making it the right height?
The video’s minimum width is set to 100% and its minimum height is also set to 100%. As the width and height of the video are auto that will allow the actual width and height to maintain their aspect ratio. This means the video will actually be much bigger than the area it occupies unless it was actually square and the viewport was square.
The video would not be centred so we move its top left position absolutely to the centre and then use transform translate to drag the middle point into the exact middle. The overflow on the parent stops the video peeking out of the container because now only the central part will be viewable.