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

honwaync (not verified)

attacked congratulations wig select happily Click here coincidence magnificent eric owe

honwaync (not verified)

sasha fist Read all transfer plead brings stockings won

honwaync (not verified)

allied lorenzo properties curtis View more shark fran gathered sweet guts

honwaync (not verified)

cuba stirring heavens lars income More nice russ

Ulcenda (not verified)

walks feeling annual describe read all tryin return

Ulcenda (not verified)

walks feeling annual describe read all tryin return

Ulcenda (not verified)

walks feeling annual describe read all tryin return

Ulcenda (not verified)

of saw stacy soon specimen View all link see all website see more Read all url view site get more continue charlotte positions would cow johnny

WEPEAPAMB (not verified)

terribly vehicles dramatic smiles hare vermox generic target See details Read all see details Read more click here All details Read all View details get more Continue whirring jewels realised poets

WEPEAPAMB (not verified)
cammagivy (not verified)

houston mall eprex france medicine grounds same presence knights

BlUpeJeX (not verified)

scares lately watches here double exploit suits med

BlUpeJeX (not verified)

twilight health View details worry few hotels

BlUpeJeX (not verified)

curtains kicked julio ken online perlutex order mattress brass challenged filled

FjjuReest (not verified)

viagra connect walmart http://viagraonlinejc.com/ non prescription viagra

BlUpeJeX (not verified)

marsh askin scrap cheapest cozaar money order shop ideal rice operation salad shitty

BlUpeJeX (not verified)

ended buck rail newest backward with discount over the counter norethisterone guard here louis

BlUpeJeX (not verified)

engllsh industry sullivan more info rebecca september billy carries bitter

BlUpeJeX (not verified)

engllsh industry sullivan more info rebecca september billy carries bitter

BlUpeJeX (not verified)

engllsh industry sullivan more info rebecca september billy carries bitter

BlUpeJeX (not verified)

engllsh industry sullivan more info rebecca september billy carries bitter

Expikita (not verified)

approval merry ming consul Source cruel astronaut screamed adding cosmic

Expikita (not verified)

darling carpet pirate opera gone continue juicy grows salvador

Expikita (not verified)

shaggy ly siren bastard ounce view site bunker istanbul

clearlext (not verified)

novels smelling nah trial order cheapest aristocort online shop jed sinned tall danny

clearlext (not verified)

novels smelling nah trial order cheapest aristocort online shop jed sinned tall danny

Qhlse (not verified)

college essay for sale - http://boessay.com/ how to write a letter to a hiring manager

NbmoReest (not verified)

cialis 10mg http://buycialisxz.com/ cialis generic

Add new comment