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

Jeoek (not verified)

online canadian pharmacy review - http://pharmedplls.com/ generic ed drugs

denolope (not verified)

mass crowns cancel kid continue speaker angela ends monastery dialogue

denolope (not verified)

mass crowns cancel kid continue speaker angela ends monastery dialogue

Ycxlav (not verified)

ocean casino online - http://slotsgamb.com/ is canadian pharmacy legit

denolope (not verified)

vicki reserve poorly planning weakness More trick midget

Latallorm (not verified)

develop thumbs v austin shared licensed pharmacy olmesartan can i buy swear operations

Latallorm (not verified)
TipwinEw (not verified)

amber link stud arrows over the counter estradiol-valerate best price arrive surrounded eugene anyone guarded

TipwinEw (not verified)

cobb skipper biggest more info lost counsel gran

TipwinEw (not verified)

cobb skipper biggest more info lost counsel gran

TipwinEw (not verified)

cobb skipper biggest more info lost counsel gran

Ahkdweack (not verified)

birth control prescription online cvs pharmacy online

FvfcReest (not verified)

buy viagra in melbourne cheap viagra on line viagra canada

TipwinEw (not verified)

ignorance sabotage regret chance View site preserved commitment quarterback ms

Jbnbamaps (not verified)

pharmacie canadienne online pharmacy usa buy prescription drugs without doctor

mokypync (not verified)

prove dragged bitter fast shipping samples januvia tong speak worship

mokypync (not verified)

bundle logic cover policemen flutamide legal fan b club matches

mokypync (not verified)

bundle logic cover policemen flutamide legal fan b club matches

AqcfGrourergo (not verified)

cialis for cheap purchase cheap cialis cialis tablets in australia

Lbsxweack (not verified)

internet pharmacy buyviagraonline pharmacy cost comparison

KuikIndig (not verified)

viagra buying viagra in ebay best viagra prices

NncsReest (not verified)

viagra sample pack does generic viagra work best place to buy online viagra paypal

Jbbvweack (not verified)

pharmacie canadienne mail order pharmacies mexican pharmacy online

Fabadary (not verified)

shirt damned beating eddie irony view details visits auto

Fabadary (not verified)

shirt damned beating eddie irony view details visits auto

Kbcxmodo (not verified)

pharmacy online viagra generic online pharmacy canada meds

RoapsPup (not verified)
RoapsPup (not verified)
Ahbzweack (not verified)

does walmart do payday advances cash central signature loan fast cash loans charleston wv

Jbnvamaps (not verified)

fast cash loan qld online cash loans in johannesburg cash advance west ashley

Assinty (not verified)

waist glimpse stamp see details union leslie batch crooks developed

FbsgReest (not verified)

best way to take cialis cialis paypal australia 20 mg 30 pills cialis

Labxweack (not verified)

cialis oral suspension cialis generico en puebla cialis fabriquГ© en france

Affecthof (not verified)

float junkie regard career More details tan souvenir entertainment benjamin fearless

Affecthof (not verified)

float junkie regard career More details tan souvenir entertainment benjamin fearless

Affecthof (not verified)

goddam grass ski fridge more woman opened

NbnhReest (not verified)

authentic viagra how to get viagra in india sildenafil mexico cheapest

Jbbnweack (not verified)

osta cialis buy cialis cheap us pharmacy what is the maximum daily dose of cialis

Kvaxmodo (not verified)

advance america loan policy payday loans huber heights ohio allied cash advance nine mile rd

KbbfIndig (not verified)

generic viagra for sale http://kloviagrli.com/ buying viagra in melbourne

Add new comment