youtube视频屏幕黑条情景

时间:2017-07-24 23:03:20

标签: html css youtube

如何制作YouTube全屏宽度和高度的视频,但是将视频设置为全尺寸,即使调整大小也完全填满整个屏幕,但我不希望这样会产生黑条调整大小时。

CSS

.video-container {
    position: relative;
    padding-bottom: 56.25%;
    padding-top: 0px; height: 0; 
    overflow: hidden;
    z-index: 1;
}
.video-container .video {
    width: 100%;
    height: 100%;
    overflow: hidden;

}

.video-container iframe,
.video-container object,
.video-container embed {
    position: fixed;
    left: 0;
    top:0;
    width: 100%;
    height: 100%;
    z-index: 1;
    overflow: hidden;
    overflow-y: hidden;
    overflow-x: hidden;
    right: 0; 
    bottom: 0;
}

HTML

<div class="video-container">
    <div class="video">
        <iframe width="853" height="480" src="https://www.youtube.com/embed/EgPRLAJB13c?autoplay=1&showinfo=0&controls=0" frameborder="0" allowfullscreen></iframe>
    </div>
</div>

1 个答案:

答案 0 :(得分:1)

在CodePen上查看视口大小以查看响应速度。
https://codepen.io/rickydam/pen/dzyEoR/left/

参考这个类似的问题。
Responsive fullscreen youtube video with no black bars?

本文总结了使用CSS嵌入响应式Youtube视频。
https://avexdesigns.com/responsive-youtube-embed/

&#13;
&#13;
.video-container {
  position: relative;
  padding-bottom: 56.25%;
  padding-top: 0px; height: 0; overflow: hidden;
}
 
.video-container iframe,
.video-container object,
.video-container embed {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
&#13;
<div class="video-container">
  <iframe src="https://www.youtube.com/embed/EgPRLAJB13c?autoplay=1&showinfo=0&controls=0" frameborder="0" allowfullscreen></iframe>
</div>
&#13;
&#13;
&#13;