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)

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

Add new comment