I tried using fill mode and this is what I get.
What I would like is not having black left and right of video, because controls also span 100% but ideally they would be the same as video width not wider.
I want to fill available area but not make video bigger than its natural size, and I dont want vertical scroll if video is bigger than it fits (so I dont use fluid option).
<script src="https://unpkg.com/video.js/dist/video.js"></script>
<link href="https://unpkg.com/video.js/dist/video-js.css" rel="stylesheet"/>
<div style="width:100%; height:300px;">
<video id="my_video" class="video-js vjs-fill" controls muted preload="auto" data-setup="{}" >
<source src="https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" type="video/mp4">
</video>
</div>
2
Answers
You can do it if you know the aspect ratio in advance
The key is to make a container for the video, which you carefully predefine to automatically grow to the desired height, based on the available width.
For a 16:9 aspect ratio, set the
padding-bottom
to 9/16 = 56.25%You should not use measure in pixels.
Give aspect-ratio:16/9; or something.
and give to video element "object-fit" property