可以't根据设备自动调整youtube播放器的大小

Can't automatic resize youtube player according to device

本文关键字:youtube 调整 播放器 可以      更新时间:2023-09-26

我是html、css、js等领域的新手。我试图自动调整youtube窗口的大小以适应设备的屏幕,但这对我不起作用。我已经尝试了这个网站上提供的许多解决方案,但似乎都不起作用。这是视频的部分代码

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%;
}

这就是我使用的。

/* 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>

实时链接

Fiddle

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

iframe{
    width: 100%;
}