Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Video slider scaling problems - CSS

Featured Replies

You need to put the video in a wapping element. Then you can set that elements height to zero, and padding bottom to a percentage value. Doing this will make that elements height be a percentage of it's width. You play around with this percentage to match the aspect ratio of the video, normally the value would be around 56%.

Then you absolutely position the iframe inside this wrapper and force it's dimensions to match.

<div class="video-wrap">
  <iframe>...</iframe>
</div>
.video-wrap {
  position: relative;
  height: 0;
  padding-bottom: 56%;
}
.video-wrap iframe {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
}

If you cannot manually put the wrapper around the iframe you can handle it with some JavaScript:

I wrote this jQuery snippet to handle this exact problem a few months ago:

(function($) {
    function makeResponsive(){
        $(this).wrap('<div class="video-wrap"></div>');
    }
    $('iframe[src*="vimeo.com"]').each(function() {
        makeResponsive.call(this);
    });
    $('iframe[src*="youtube.com"]').each(function() {
        makeResponsive.call(this);
    });
}(jQuery));

Edited by rbrtsmith

Only thing to add to what rbrtsmith said is that the padding should be 56.25% for 16:9 videos (9 / 16 = 0.5625, x 100 = 56.25) and 75% for 4:3 videos (3 / 4 = 0.75, x 100 = 75) although 16:9 is the most common aspect ratio online.

http://webdesignerwall.com/tutorials/css-elastic-videos is another version of the same, only requires CSS.

 

That's pretty much exactly the same as the css I posted earlier. The js is only required when you're using a cms and you want clients to be able to add a video to the body of the post, as the iframe will not get the required wrapper. The js merely adds this wrapper if this situation were to arise.

Edited by rbrtsmith

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.