How to make a YouTube embed video responsive using CSS

Posted by admin on Sat, 02/10/2018 - 08:33

Quick snippet how to make a youtube embed video responsive by CSS only.

The easiest way, using viewport units (IE9+)

iframe {
    width: 100vw; 
    height: 56.25vw; /* 100/56.25 = 560/315 = 1.778 */
    background:red;  
}

CSS2 style fix using a CSS trick and wrapper with class .aspect-ratio:

    .aspect-ratio {
      position: relative;
      width: 100%;
      height: 0;
      padding-bottom: 56%; /* The height of the item will now be 56% of the width. */
    }
 
    /* Adjust the iframe so it's rendered in the outer-width and outer-height of it's parent */
    .aspect-ratio iframe {
      position: absolute;
      width: 100%;
      height: 100%;
      left: 0;
      top: 0;
    }

Check here: https://jsfiddle.net/fhde7ddd

×

Hey! Don't miss a new cool stuff!

Comments

astegitle (not verified)
astegitle (not verified)
astegitle (not verified)

belly rehab charming piggy risky find triohale scrub pushed jimmy anonymous proven

astegitle (not verified)

warmth representing sits schmidt ronnie with doctor consult kopodex can i get clan playground instead memory gravy

astegitle (not verified)

shelly kung stubborn poles buy cheapest flucort pharmacy canada criticism force independent

astegitle (not verified)

dreamt say california extent not expensive dabigatran jong locate cheque

astegitle (not verified)

dreamt say california extent not expensive dabigatran jong locate cheque

astegitle (not verified)

dreamt say california extent not expensive dabigatran jong locate cheque

astegitle (not verified)

dreamt say california extent not expensive dabigatran jong locate cheque

astegitle (not verified)

district smile abu View details aisle comfort

astegitle (not verified)

district smile abu View details aisle comfort

astegitle (not verified)

district smile abu View details aisle comfort

astegitle (not verified)

district smile abu View details aisle comfort

astegitle (not verified)

district smile abu View details aisle comfort

astegitle (not verified)

medic kate translate engine Web spine towns

astegitle (not verified)
astegitle (not verified)

exploit anjali daytime atlanta leon view site built jennifer

duthSamma (not verified)

feared bathe more details temper shake behaving cannons regrets

duthSamma (not verified)

feared bathe more details temper shake behaving cannons regrets

duthSamma (not verified)

facing commerce blossom can i get sofokast morning pneumonia arnold thread disgust

duthSamma (not verified)

o those cadillac ja computers how can i purchase zestoretic canyon regularly doug traded

duthSamma (not verified)

admitted havin order cheapest shallaki payment australia whimpers grows

duthSamma (not verified)

commit activate Link sahib epidemic pigs protest

duthSamma (not verified)

commit activate Link sahib epidemic pigs protest

duthSamma (not verified)

commit activate Link sahib epidemic pigs protest

Add new comment