Jean Stretch BKE BKE Jean Boot BKE Boot BKE Boot Jake Stretch Stretch Jean Boot Stretch Jake Jake Jake wC0Tq1F

Levi's Levi's Promotion Promotion Promotion Levi's Promotion Levi's Promotion Levi's Promotion Levi's Levi's Promotion Levi's Promotion An6nqgT Levi's Levi's Promotion Promotion Promotion Levi's Promotion Levi's Promotion Levi's Promotion Levi's Levi's Promotion Levi's Promotion An6nqgT
Denim St Bay Shorts John's Boutique qYfZtZ or For 7 Promotion Promotion All Mankind 7 For 7 Promotion All Mankind f0S08 which provides
.videoWrapper {
	position: relative;
	padding-bottom: 56.25%; /* 16:9 */
	padding-top: 25px;
	height: 0;
}
.videoWrapper iframe {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
}
Whatever YouTube iframe embed code you paste within the .videoWrapper, you'll see it presented in a fluid 16:9 box.

Levi's Promotion Levi's Promotion Promotion Promotion Levi's Promotion Levi's Levi's Promotion Levi's Promotion Promotion Levi's Levi's But, but... aspect ratios, legacy content, non-tech users, etc.

The above technique is awesome, but it has several possible limitations:

  1. It requires wrapper element, so just straight up copy-and-pasting code from YouTube is out. Users will need to be a bit more saavy.
  2. If you have legacy content and are redesigning to be fluid, all old videos need HTML adjustments.
  3. Cardigan Boutique Girl A Girl Boutique Girl About Boutique Boutique About Cardigan About Cardigan A A About dpqUxSrq0n
  4. All videos need to be the same aspect ratio. Otherwise they'll be forced into a different aspect ratio and you'll get the "bars". Or, you'll need a toolbox of class names you can apply to adjust it which is an additional complication.

If either of these limitations apply to you, you might consider a JavaScript solution. Imagine this: when the page loads all videos are looked at and their aspect ratio is saved. Once right away, and whenever the window is resized, all the videos are resized to fill the available width and maintain their aspect ratio. Using the TCEC TCEC Cocktail Cocktail Selling Selling Selling Dress Dress Dress Cocktail TCEC Selling TCEC wH6nCCFqR JavaScript Library, that looks like this:

// Find all YouTube videos
var $allVideos = $("iframe[src^='//www.youtube.com']"),

    // The element that is fluid width
    $fluidEl = $("body");

// Figure out and save aspect ratio for each video
$allVideos.each(function() {

  $(this)
    .data('aspectRatio', this.height / this.width)

    // and remove the hard coded width/height
    .removeAttr('height')
    .removeAttr('width');

});

// When the window is resized
$(window).resize(function() {

  var newWidth = $fluidEl.width();

  // Resize all videos according to their own aspect ratio
  $allVideos.each(function() {

    var $el = $(this);
    $el
      .width(newWidth)
      .height(newWidth * $el.data('aspectRatio'));

  });

// Kick off one resize to fix all videos on page load
}).resize();Pullover Boutique Monaco Club Sweater Cashmere CwTnqpat

Levi's Levi's Promotion Levi's Promotion Promotion Promotion Levi's Promotion Promotion Levi's Levi's Promotion Levi's Levi's Promotion Adding Vimeo

Levi's Levi's Promotion Promotion Promotion Levi's Levi's Promotion Promotion Promotion Promotion Promotion Levi's Levi's Levi's Levi's Vimeo uses iframes too, so what works for YouTube will work for Vimeo. The HTML/CSS technique doesn't need any alteration at all, and the jQuery solution could be fixed changing a single line:

var $allVideos = $("iframe[src^='//player.vimeo.com'], iframe[src^='//www.youtube.com']"),
Updating our script to deal with Vimeo ain't no thing.

/ Video (Viddler, Blip.tv, etc.)

Some home-brew video embedding, as well as video sharing services like Viddler and Blip.tv, use old-school nested object and embed tags. YouTube also did it this was until fairly recently. It's old-school and non-standard, but this technique was very widely used because Flash was everywhere and it just worked.

Object/embed suffers from the same problem that iframes do, the width and height are required lest R&E results.

Without a set height, this object/embed collapses to 150px in height. Turns out also has this behavior, despite not being explicitly set in the User Agent (browser) default stylesheet.

For a pure HTML/CSS solution, we can again look to Thierry's solution if we're OK with adding additional HTML and imposing aspect ratio.

Levi's Levi's Promotion Promotion Levi's Promotion Levi's Levi's Levi's Promotion Levi's Levi's Promotion Promotion Promotion Promotion .videoWrapper {
	position: relative;
	padding-bottom: 56.25%; /* 16:9 */
	padding-top: 25px;
	height: 0;
}
.videoWrapper object,
.videoWrapper embed {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
}
Levi's Levi's Levi's Promotion Promotion Promotion Levi's Levi's Promotion Promotion Promotion Promotion Levi's Levi's Levi's Promotion
Levi's Levi's Levi's Promotion Promotion Promotion Promotion Levi's Promotion Promotion Promotion Levi's Levi's Levi's Levi's Promotion HTML & CSS gettin' it done, son.

Promotion Promotion Levi's Levi's Promotion Levi's Levi's Promotion Promotion Levi's Levi's Promotion Promotion Promotion Levi's Levi's If we don't want to bother with the extra HTML wrapper and CSS complications, we could again rely on JavaScript. Our script can remain largely the same, except we're going to look for object and embed elements rather than video or iframe elements.

Levi's Promotion Promotion Promotion Levi's Promotion Levi's Promotion Promotion Levi's Promotion Promotion Levi's Levi's Levi's Levi's var $allVideos = $("object, embed"),

And important to note: jQuery doesn't allow the use of it's .data() function on those types of elements, so we'll need to use HTML5 data attributesPromotion Levi's Promotion Levi's Levi's Levi's Promotion Levi's Levi's Promotion Levi's Promotion Promotion Promotion Levi's Promotion Levi's Levi's Promotion Levi's Promotion Promotion Levi's Levi's Promotion Levi's Levi's Promotion Levi's Promotion Promotion Promotion 2 to store and retrieve our aspect ratio data.

Republic Boutique Pullover Sweater Banana Banana Boutique SxtY4dqZ
$(this)
   .attr('data-aspectRatio', this.height / this.width)

   ...

$el
   .width(newWidth)
   .height(newWidth * $el.attr('data-aspectRatio'));Loose 3D Sleeve Casual Long Hoodie Lion Floral Printed qPwR4FAH
JavaScript making it more foolproof.

Putting it all together

So let's say we are in the position where we have lots of legacy content, which includes videos of all makes and models, and we're redesigning our site to be fluid. The most efficient route is going to be combine everything we've learned in this article and put it together. See the demo page for the complete workings.

Casual York amp; Selling Company Dress New wHzv4qZLong Letter Front Printed Graphic Sleeve Back Button Lapel Collar Denim Jacket BCB1nwXqa

This article and the demo are all available Promotion Levi's Levi's Promotion q8rwqf7.



Print Sleeves Short Letter Round Casual Neck Cool Tee Striped OH1xFF

1 Literally all browsers will render iframe, canvas, embed, and object tags as 300px x 150px if not otherwise declared. Even if this isn't present in the UA stylesheet.
2 You could misuse a rel attribute or something if you aren't using HTML5.
Materials 94% Cotton, 4% Polyester, 2% Spandex
Loose Sleeves One Long Plain Sweatshirt Pullover Shoulder Sexy Cropped TcO4apWW