无法根据设备自动调整 youtube 播放器的大小

Can't automatic resize youtube player according to device

我是 html、css、js 等领域的新手。我正在尝试自动调整 youtube window 的大小以适应设备的屏幕,但它对我不起作用. 我尝试了本网站提供的许多解决方案,但似乎没有任何效果。 这是视频的部分代码

HTML

 <div class="wrapper">
      <div class="h-iframe">
           <iframe  class="center-block" src="https://www.youtube.com/embed/Npa-z3P1FTY" frameborder="0" allowfullscreen></iframe>
      </div>
 </div>

CSS

.h_iframe iframe {
  position:absolute;
  top:0;
  left:0;
  width:100%; 
  height:100%;
}

.center-block {
    display: block;
    margin-left: auto;
    margin-right: auto;
 }

.wrapper {
    position: relative;
    width: 100%;
}

Fiddle

您不需要调用 .h_iframe iframe,然后在下方调用 .center_block(这是您的 iframe 中 class 的名称)以及:

iframe{
    width: 100%;
}

这是我用的。

/* Flexible iFrame */

.flexible-container {
  position: relative;
  padding-bottom: 56.25%;
  padding-top: 30px;
  height: 0;
  overflow: hidden;
}

.flexible-container iframe,
.flexible-container object,
.flexible-container embed {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
<!-- Responsive iFrame -->
<div class="flexible-container">
<iframe src="https://b922bde52f23a8481830-83cb7d8d544f653b52d1a1621f05ea9d.ssl.cf3.rackcdn.com/video/landingpage.mp4" frameborder="0" style="border:0"></iframe>
</div>

live link