html - 保持无法创建垂直滚动条且无法剪辑的纵横比框
问题描述
问题: 如何确保我的视频保持纵横比 (16x9) 并且不会在非常小的高度视口上创建滚动条,而不是剪辑。
重新创建:
使用底部边缘使浏览器窗口变得非常宽和非常短,您将看到窗口现在有一个滚动条。
.wrapper {
background: green;
height: 100%;
width: 50%;
margin: 0 auto;
}
.video {
background: red;
overflow: hidden;
max-height: 0;
padding-top: 56.25%;
}
<div class="wrapper">
<div class="video">123</div>
</div>
解决方案
您可以考虑max-width
基于vh
单位定义的 a:
.wrapper {
background: green;
height: 100%;
width: 50%;
margin: 0 auto;
max-width: 160vh;
/* the 56.25% of this value should be less or equal to 100vh considering margin/padding/border
In this case with 8px of body margin the max value should be:
calc((100vh - 16px)*100/56.25)
*/
}
.video {
background: red;
overflow: hidden;
max-height: 0;
padding-top: 56.25%;
}
<div class="wrapper">
<div class="video">123</div>
</div>
推荐阅读
- android - Android Emulator (Android Studio AVD) 串口连接 - 空设备列表
- c - 如何提高用 C 编写的阻塞队列的性能?
- raspberry-pi - 打开/初始化选定的 video_out (-vo) 设备时出错
- mongodb - Mongo DB 查询更新集合中的文档的难题
- list - 正整数和负整数
- node.js - 将祖鲁时间转换为 +8GMT
- python - 我在做机器学习,我被困在列表理解的一条线上
- github - 如何在同一个 GitHub Workflow 中为作业设置不同的条件?
- rust - 恐慌!()和期望()的替代品--release?
- r - Y标签重叠ggplot和排序