【问题标题】:Video column height match [duplicate]视频列高匹配[重复]
【发布时间】:2018-03-14 14:38:52
【问题描述】:

我有一个两列部分,一侧包含视频,另一侧包含文本。

它们都是 50% 的宽度,我希望它们具有相同的高度,因为它们一起向下响应

section {
  width: 1000px;
}

.half {
  width: 50%;
  position: relative;
  float: left;
}

.grey {
  background: #f5f5f5;
}
<section>
  <div class="half grey one">
    <p>text goes here.</p>
  </div>
  <div class="half">
<iframe  src="https://www.youtube.com/embed/8kyWDhB_QeI" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
  </div>
</section>

左栏中的文本也需要始终保持居中,水平和垂直。

【问题讨论】:

    标签: html css multiple-columns


    【解决方案1】:

    您可以使用 Flexbox

    section {
      display: flex; /* displays flex-items (children) inline where the height of all items is dictated by the height of the "tallest" one (achieved by the default "align-items: stretch") */
      width: 1000px;
    }
    
    .half {
      width: 50%;
      position: relative;
      /*float: left; not necessary */
    }
    
    .grey {
      display: flex;
      justify-content: center; /* horizontally centered */
      align-items: center; /* vertically centered */
      background: #f5f5f5;
    }
    <section>
      <div class="half grey one">
        <p>text goes here.</p>
      </div>
      <div class="half">
        <iframe  src="https://www.youtube.com/embed/8kyWDhB_QeI" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
      </div>
    </section>

    【讨论】:

    • 我注意到当左侧 div 中有多个项目不再相互堆叠时,它们会并排放置。例如,我有三个不同的模块:标题、文本和按钮。通过添加您提供的代码,它们彼此堆叠在一起。
    • 只需将flex-direction: column 添加到父级或.grey 即可垂直堆叠弹性项目或子级。
    猜你喜欢
    • 1970-01-01
    • 2015-07-18
    • 2016-08-31
    • 1970-01-01
    • 2011-09-28
    • 2016-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多