Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
22
Help us understand the problem. What is going on with this article?

More than 3 years have passed since last update.

@0084ken

[YouTube] iframeのレスポンシブ対応

iframeをレスポンシブ対応した時のメモです。
今回はYouTubeを使用例として。

HTML

<div class="frame-wrapper__video">
  <iframe src="https://www.youtube.com/hoge/hogehogehogehogehoge" frameborder="0" allowfullscreen></iframe>
</div>
  • YouTubeから取得したiframeを div で囲う。

CSS

.frame-wrapper__video {
  position: relative;
  width: 100%;
  height: 0;
  padding-bottom: 56.25%;
  overflow: hidden;
  margin-bottom: 50px;
}

.frame-wrapper__video iframe {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}
  • 4:3の場合 padding-bottom: 75%;
  • 16:9の場合 padding-bottom: 56.25%;
  • padding-bottompadding-topでも可。

サンプル

表示サンプルは下記で確認できます。

GitHub Pages

GitHubリポジトリ

参考

CSSだけでどんな画像でも4:3や16:9の比率を維持して配置する方法

22
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
22
Help us understand the problem. What is going on with this article?