A
A
Alexey Napechkin2016-04-26 14:43:07
YouTube
Alexey Napechkin, 2016-04-26 14:43:07

Html code for a YouTube video, is it possible to stretch height relative to width?

What can be specified in height so that the height automatically adjusts to the width and there is no black background on the sides of the video? auto <- doesn't work.

<iframe width="100%" height="" src="https://www.youtube.com/embed/Zh1zprk92s8" frameborder="0" allowfullscreen></iframe>

039229d0fa474b4598283d5c88db266a.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anna_BS, 2016-04-26
@mypage93

.video {
    height: 0;
    position: relative;
    padding-bottom: 56.25%;
}
.video iframe {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
}

code pen

T
tecs, 2020-03-09
@tecs

thanks a lot.
I'll just add for the pioneers:

<div class="video">
  <iframe id="youtube1" width="100%" src="https://www.youtube.com/embed/nWdInJYfcOY?controls=0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question