【问题标题】:horiontally aligning youtube responsive youtube videos水平对齐 youtube 响应式 youtube 视频
【发布时间】:2018-09-24 02:12:39
【问题描述】:

我正在尝试使用 flexbox 并排嵌入两个视频(一个来自 youtube,一个来自 facebook),但我需要让它们具有响应性。我浏览了网站上的其他问题,它们很有帮助,但我仍然遇到左侧视频显示 2 倍于右侧视频高度的问题。任何人都可以看看,让我知道我做错了什么?提前致谢。

<div class="video">
  <div class="video-header">
    <h1>VIDEO</h1>
  </div>

  <div class="youtube-top">

    <div class="video-responsive1">
      <iframe width="650" height="350" src="https://www.youtube.com/embed/gghVoRX-sn0?rel=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
    </div>

    <div class="video-responsive2">
      <iframe src="https://www.facebook.com/plugins/video.php?href=https%3A%2F%2Fwww.facebook.com%2Fdjtrentino%2Fvideos%2F10153921589011137%2F&show_text=0&width=560" width="650" height="350" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true" allowFullScreen="true"></iframe>
    </div>

  </div>
</div>


.youtube-top {
  display: flex;
  justify-content: center;
  align-items: center;
}

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

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

.video-responsive1,
.video-responsive2{
  flex: 1;
}

video image - rendering incorrectly

【问题讨论】:

    标签: html css responsive-design youtube flexbox


    【解决方案1】:

    Here's my solution on codepen.

    HTML

    <div class="video">
      <div class="video-header">
        <h1>VIDEO</h1>
      </div>
    
      <div class="video-container">
    
        <div class="video-responsive">
          <div class="aspect-ratio-16-9">
            <iframe src="https://www.youtube.com/embed/gghVoRX-sn0?rel=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>  
          </div>
    
        </div>
    
        <div class="video-responsive">
          <div class="aspect-ratio-16-9">
            <iframe src="https://www.facebook.com/plugins/video.php?href=https%3A%2F%2Fwww.facebook.com%2Fdjtrentino%2Fvideos%2F10153921589011137%2F&show_text=0&width=560" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true" allowFullScreen="true"></iframe>
          </div>
        </div>
    
      </div>
    </div>
    

    CSS

    .video-responsive {
      width: 50%;
      display: inline-block;
      height: 56.25%;
      margin: 0 -1px;
    }
    
    .aspect-ratio-16-9 {
      width: 100%;
      padding-top: 56.25%; 
      position: relative;
    }
    
    .video-responsive iframe {
      width: 100%;
      height: 100%;
      position: absolute;
      top: 0;
    }
    

    一般cmets:

    1. 您不需要弹性。 Flex 适用于您不知道内容的宽度,或者您需要垂直对齐内容的情况。使用display: block 在这里工作得很好,有孩子width: 50%。注意margin: 0 -1px,这只是一个快速修复,因为display: inline-block 会创建额外的水平填充。
    2. 您不需要在 HTML 中设置宽度/高度。你可以,而且我确信有设置它的建议;我的解决方案没有。
    3. 您需要一个纵横比类。这会将孩子限制在适当的大小。
    4. 学习和使用 BEM 进行类命名。使用 video-responsive12 会使代码的阅读和调试更加混乱,在这种情况下,您甚至不需要它们不同。

    【讨论】:

    • 谢谢!这非常有效。我仍在学习很多这方面的知识,因此非常感谢您的帮助。
    • @cubs_fan35 如果有效,请将问题标记为已解决 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-02
    • 2015-05-05
    • 2019-04-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多