html - Html 视频长宽比
问题描述
我正在尝试构建一个具有 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;
}
但到目前为止它不起作用,视频的高度总是大于视口,因此垂直滚动条。
解决方案
您走在正确的道路上,但我想您想知道为什么视频会占据全屏/视口。在您的示例中,您没有为 .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>
推荐阅读
- java - 我们可以解密使用不同算法加密的密文吗?
- vim - 在右、左、上、下打开新窗口
- c++ - 为什么这个结构的移动赋值运算符被删除了?
- delphi - 保持重点小组行
- android-studio - 为什么在 Android Studio 中我找不到要为 XML 布局中的视图添加的大部分属性,例如填充、textSize 等
- javascript - 多部分表单,字段/文件的顺序
- ansible - Openshift + Ansible:在引导时播放批准节点证书时失败
- ios - 如何通过 AVPlayer iOS 以 2.0 的速率播放带有音频的视频
- blockchain - Corda Node 如何支持水平缩放?
- dynamics-crm - 尝试使用 Xrm.WebApi 从 Dynamics CRM 2016 读取自定义字段