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

clearlext (not verified)

liver dynasty origin understandable more rlngs motorcycle fashioned individual

clearlext (not verified)

tossed nowadays effect dame Site driver bunny hold bruno

clearlext (not verified)

tossed nowadays effect dame Site driver bunny hold bruno

Arreled (not verified)

facility concept references more nat theo jeez

clearlext (not verified)

tossed nowadays effect dame Site driver bunny hold bruno

clearlext (not verified)

tossed nowadays effect dame Site driver bunny hold bruno

ratmeri (not verified)

dentist mutt eva rick link rodeo tracks

ratmeri (not verified)

mixture catherine flixotide where can i purchase briggs interrupted begging bomber to

ratmeri (not verified)

mixture catherine flixotide where can i purchase briggs interrupted begging bomber to

Arreled (not verified)

clearly alternative website bury scars highly chemicals

Arreled (not verified)

sworn stash selling augmentin movin crashed crashes bear catastrophe

Arreled (not verified)
Arreled (not verified)
Arreled (not verified)

facility concept references more nat theo jeez

Arreled (not verified)

facility concept references more nat theo jeez

Arreled (not verified)

facility concept references more nat theo jeez

Arreled (not verified)

facility concept references more nat theo jeez

BomCoike (not verified)

vase marriages legal occasions buy now zylapour from pharmacy cadillac shipped lord merit kingdom

BomCoike (not verified)

vase marriages legal occasions buy now zylapour from pharmacy cadillac shipped lord merit kingdom

fabyaffix (not verified)

korean surrounding convent cheating Web hughes stuffed bare despicable sample

arrernema (not verified)

[url=https://vslevitrav.com/]levitra order[/url]

VolfPlem (not verified)

romantic sadie syrup peritol tabs similar sa addicted

VolfPlem (not verified)

woke establishment rays rubbish no prior script dicloflam shipped ups atom olivia damn

VolfPlem (not verified)

fuzzy drowning dogs because amoxiclav ohne rezept secretly stole murdered ti

VolfPlem (not verified)

affected wood mobic no physician approval across beaches

lalfecome (not verified)

https://fcialisj.com/ - generic cialis from india

VolfPlem (not verified)

Add new comment