javascript - 设置位置背景视频html5

标签 javascript css html video

在全屏模式下,我想将视频设置在中间垂直位置。
我可以通过更改 video.fillWidth 上的 bottom: 0;top: 0; 将视频放在顶部或底部类,但我无法将其设置在中间位置。

我想要这样:

enter image description here

CSS:

.header-unit {
    position: relative;
    height: 600px;
}

video {
    display: inline-block;
}

#video-container {
    z-index: -1;
    position: absolute;
    right: 0;
    left: 0;
    top: 0;
    bottom: 0;
    overflow: hidden;
}

video.fillWidth {
    bottom: 0;
    position: absolute;
    width: 100%;
}

@media (max-width: 1099px){
    video.fillWidth{
        height:100%;
        width:auto
    }
}

HTML:

<div class="header-unit">
    <div id="video-container">
        <video autoplay loop class="fillWidth">
            <source src="movie.mp4" type="video/mp4"/>
        </video>
    </div><!-- end video-container -->
</div><!-- end .header-unit -->

最佳答案

试试这个。

CSS:

video.fillWidth {
    position: absolute;
    width: 100%;
    top: 50%;
    transform: translateY(-50%);
}

关于javascript - 设置位置背景视频html5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28728083/

相关文章:

javascript - 基于几个多选框过滤结果,vue

javascript - 如何在webgl中设置模型 View 矩阵中旋转的枢轴

css transform 翻译右上角

css - 对于简短的外语单词组,我应该使用哪个元素?

javascript - 无法使用 javascript 从 html 中获取我的 id 来给它们提供样式

javascript - CSS:将三个按钮对齐成两行

html - 将 div 定位在具有绝对位置的 div 下方

html - CSS div 部分重叠

javascript - 在 Canvas 中间创建等边三 Angular 形?

javascript - 如何从父组件调用子组件函数?