【问题标题】:Html video aspect ratioHtml 视频长宽比
【发布时间】:2020-07-19 07:58:36
【问题描述】:

我正在尝试构建一个具有 16/9 纵横比的简单 html 视频播放器

<div class="video-container">
        <video  controls class="video">
            <source src="/text.mp4" type="video/mp4" />
        </video>
</div>

.video-container {
  position: relative;
  padding-bottom: 56.25%;
  padding-top: 25px;
  height: 0;
}

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

但到目前为止它不起作用,视频的高度总是大于视口,因此是垂直滚动条。

【问题讨论】:

标签: html css video aspect-ratio


【解决方案1】:

您走在正确的道路上,但我想您想知道为什么视频会占据全屏/视口。在您的示例中,您没有为 .video-container 提供父 div 并指定大小:

.parent {
  width: 500px;
}

.video-container {
  position: relative;
  padding-bottom: 56.25%;
  padding-top: 25px;
  height: 0;
}

.video {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}
<div class="parent">
      <div class="video-container">
        <video controls class="video">
          <source src="/text.mp4" type="video/mp4" />
        </video>
      </div>
    </div>

【讨论】:

  • 这很好,但我想要一个视频高度和宽度始终是浏览器内部高度和宽度的情况。当我将 src 设置为 16/9 视频时,我总是有一个垂直滚动条
猜你喜欢
  • 1970-01-01
  • 2011-04-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-02
  • 2011-09-10
  • 2011-06-27
  • 1970-01-01
相关资源
最近更新 更多