Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fullscreen video without black borders

The problem I have is that the video always gets black bars on the sides or on the top/bottom depending on the screen size.

enter image description here

Any idea how to get it full screen always without showing that annoying black bars? and without using a plugin.

This is my markup:

    <div id="full-bg">
        <div class="box iframe-box" width="1280" height="800">
            <iframe src="http://player.vimeo.com/video/67794477?title=0&amp;byline=0&amp;portrait=0&amp;color=0fb0d4" width="1280" height="720" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
        </div>
    </div>
    #full-bg{
        width: 100%;
        height: 100%;
        img{
            display: none;
        }
        .iframe-box{
            width: 100%;
            height: 100%;
            position: absolute;
            background: url(../img/fittobox.png);
            left: 0 !important;
            top: 0 !important;
            iframe{
                width: 100%;
                height: 100%;
            }
        }
    }
like image 689
codek Avatar asked Jun 07 '13 12:06

codek


2 Answers

Try adding to your CSS

.iframe-box {
    max-width: 1280px; /* video width */
    max-height: 720px; /* video height */
}

This means that width: 100%; height: 100% will let the element will expand as much as it can, until it hits a maximum height or width of 720px or 1280px, respectively.

If the screen you're viewing it on has a greater resolution, the node will stop expanding and you'll not have black borders.


Further, afaik the following is not valid CSS, are you using a library or something?

#full-bg {
    .iframe-box {
        foo: bar;
    }
}

Edit after answer accepted: I just thought of a completely different way to achieve this, but it would require you to change a lot of your CSS

.fittobox {                /* give fit to box an aspect ratio */
    display: inline-block; /* let it be styled thusly */
    padding: 0;            /* get rid of pre-styling */
    margin: 0;
    width: 100%;           /* take up full width available */
    padding-top: 56.25%;   /* give aspect ratio of 16:9; "720 / 1280 = 0.5625" */
    height: 0px;           /* don't want it to expand beyond padding */
    position: relative;    /* allow for absolute positioning of child elements */
}

.fittobox > iframe {
    position: absolute;    /* expand to fill */
    top: 0px;
    left: 0px;
    right: 0px;
    bottom: 0px;
}
like image 137
Paul S. Avatar answered Sep 21 '22 14:09

Paul S.


If you know the aspect ratio of your video, you shouldn't even need Javascript. You can use a percentage-based padding-top.

I could post code, but I'd recommend you read this entire article anyway.

like image 25
GusRuss89 Avatar answered Sep 19 '22 14:09

GusRuss89