html - 全屏背景视频不适用于 18 :9 mobile devices

标签 html css sass

我为这个网站实现了一个全屏背景视频https://www.yu-performance.at使用下面的代码。它在台式机和大多数移动设备上运行良好。只有在 18:9 格式的移动设备上,视频上方和下方才有空白,如下所示,但我希望视频在 18:9 设备上也能全屏显示。有谁知道为什么会这样?

18:9 设备上带有空白的视频: screenshot mobile 18:9

该网站在第一部分有一个背景视频,模拟为背景大小封面,使用以下样式:

//container div
.banner {
    position: relative;
    overflow: hidden;
    width: 100%;
    height: 100%;

    //fullsize background video
    video {
        position: absolute;
        top: 50%;
        left: 50%;
        min-width: 1000%;
        min-height: 1000%;
        width: auto;
        height: auto;
        z-index: -100;
        transform: translate(-50%, -50%) scale(0.1005);
    }

最佳答案

问题是视频是 16:9,而在 18:9 的移动设备上,视频不会填满整个视口(viewport)。所以我为只有 18:9 的设备编写了另一个媒体查询,强制视频调整到全窗口高度,然后视频将自动覆盖整个屏幕,因为放大后的 16:9 视频的宽度将大于屏幕宽度。

    @media screen and (max-aspect-ratio: 9/18) and (orientation: portrait) {
        video {
            min-width: 100% !important;
            min-height: 100% !important;
            width: auto !important;
            height: 100% !important;
            transform: translate(-50%, -50%) scale(1.0) !important;
        }
    }

关于html - 全屏背景视频不适用于 18 :9 mobile devices,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59489045/

相关文章:

html - 在移动 View 中单击时菜单不会展开

javascript - 使用javascript修改嵌套在div中的html元素

css - 为什么,如果 CSS 属性在之后声明,会被之前的一些声明覆盖

css - 根据媒体查询更改变量值

angular - 如何在其他scss文件中使用 Angular Material 主题颜色变量

javascript - 将innerHTML 抓取到变量中

html - 谷歌折线图中的图例图标宽度变化

html - 具有子跨度的 100% 宽度 div 不会右对齐

javascript - 如何在运行时在单击事件时更改 html 按钮的类?

php - 表中的不同链接