Milan Milan - 1 year ago 217
CSS Question

Video 100% width and height

I have a video, and I want it to FILL 100% of the width, and 100% of the height. And keep the aspect ratio.

Is it possible that it at least fills 100% for both? And if a bit of the video has to be out of the screen to keep the aspect ratio, that doesn't matter.


<video preload="auto" class="videot" id="videot" height="100%" preload>
<source src="BESTANDEN/video/tible.mp4" type="video/mp4" >
<object data="BESTANDEN/video/tible.mp4" height="1080">
<param name="wmode" value="transparent">
<param name="autoplay" value="false" >
<param name="loop" value="false" >


.videof, .videot {
width: 100% !important;
height: 100% !important;

Answer Source

You can use Javascript to dynamically set the height to 100% of the window and then center it using a negative left margin based on the ratio of video width to window width.

var $video  = $('video'),
    $window = $(window); 

    var height = $window.height();
    $video.css('height', height);

    var videoWidth = $video.width(),
        windowWidth = $window.width(),
    marginLeftAdjust =   (windowWidth - videoWidth) / 2;

        'height': height, 
        'marginLeft' : marginLeftAdjust
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download