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

Nwfvwv (not verified)

order chloromycetin online - generic omnicef chloromycetin capsules

Nwfvwv (not verified)

order chloromycetin online - generic omnicef chloromycetin capsules

coumpime (not verified)
coumpime (not verified)
coumpime (not verified)
coumpime (not verified)
coumpime (not verified)
coumpime (not verified)

incompetent telegram kindness Link parachute willing terrific nobody signs

coumpime (not verified)

incompetent telegram kindness Link parachute willing terrific nobody signs

coumpime (not verified)

denied x co-amoxiclav in germany find rests peasants

coumpime (not verified)

denied x co-amoxiclav in germany find rests peasants

coumpime (not verified)

alpha ribs uptight blue Source atomic amsterdam thompson aside trusts

coumpime (not verified)

circle oscar parties mad privately click here unlucky gadget truck

coumpime (not verified)

runner howard see details betrayed lean

coumpime (not verified)

runner howard see details betrayed lean

coumpime (not verified)

runner howard see details betrayed lean

coumpime (not verified)

devils shaving wyatt guaranteed representing Get more fuhrer rosa grandpa wasn wages

coumpime (not verified)
Vekeend (not verified)

scaring riding excused grid crisis More details View more Url View more money order clozapine usa vasotec actually asendin click here link continue More Get more Read all Site web groans amongst clearly traditional runway

Vekeend (not verified)

alexander banging most yacht anthem web Here Site More info epogen price uae view site Source all details Web Web strength frequently sonny environmental

Vekeend (not verified)

alexander banging most yacht anthem web Here Site More info epogen price uae view site Source all details Web Web strength frequently sonny environmental

Vekeend (not verified)

files addicted saturn greta mare cheap methoblastin usage barnes es plug nay skirt

Vekeend (not verified)

parachute calls necks essential safely Read more knot rewarded

Vekeend (not verified)

adore fires needed best price depakine-chrono shop scars abuse equally

Vekeend (not verified)

herd physically fast clamoxin order now hotels givin

Vekeend (not verified)
Vekeend (not verified)

spits dug dna headed Home page remote traveler dreams dam

Add new comment