使用媒体查询时尝试将背景视频居中

时间:2019-01-31 07:37:13

标签: html css video media-queries html5-video

这不可能吗?整个上午一直在尝试将视频放置在中央或尝试将视频的大小更改为较小,以便它至少适合视频的关键部分,以便用户可以在移动设备上观看。最好的解决方案是什么?我已经进行了很多研究,但在此方面找不到任何帮助,让我感到奇怪的是,这在CSS中要求太多了吗?除非有其他选择...请让我知道!非常感谢!

* {
box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Courier New', Courier, monospace;
    font-size: 1rem;
    line-height: 1.5;
    color: #333;
    overflow-x: hidden;
    background-color: whitesmoke;
}

.para {
    font-size: 1.5em;
    margin: auto 10px;;
}

.v-header {
    height: 99vh;
    display: flex;
    align-items: center;
    color: #fff;
}

#jsc {
/*display: none;*/
}

.container {
    max-width: 960px;
    padding-left: 1rem;
    padding-left: 1rem;
    margin: auto;
    text-align: center;
}
.container h1 {
    font-size: 2.5em;
}

section {
    display: flex;
}

.fullscreen-video-wrap {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

.fullscreen-video-wrap video {
    min-width: 100%;
    min-height: 100%;
}

#heading {
    font-family: 'Coiny', cursive;
    color: white;
    font-size: 3rem;
    display: none;
}

.header-overlay {
    height: 100vh;
    width: 100vw;
    position: absolute;
    top: 0;
    left: 0;
    background: #225470;
    z-index: 1;
    opacity: 0.65;
}

.header-content {
    z-index: 2;
}

.header-content .jsc {
    margin-bottom: 0;
}

.header-content .jsc {
    font-size: 1.5rem;
    display: block;
    padding-bottom: 2rem;
}

.btn {
    background: #34b3a0;
    color: #fff;
    font-size: 1.2rem;
    padding: 1rem 2rem;
    text-decoration: none;
}


@media only screen 
and (min-device-width : 375px) 
and (max-device-width : 667px) 
and (orientation : portrait) { 

    #jsc {
        height: 150px;
        width: 150px;
    }

    .fullscreen-video-wrap {
        position: absolute;
        top: 50px;
        right: 100px;
    }
}

        <div class="fullscreen-video-wrap">

    <video src="seaturtle.mp4" autoplay="true" loop="true" muted="true"></video>

        </div>

    <div class="header-overlay"></div>  
    <div class="header-content">

        <img id="jsc" src="jscc.png">
        <h3 id="heading">Personal Training</h3>
             <a href="#" class="btn">Contact Me</a>
    </div>  

</header>

1 个答案:

答案 0 :(得分:0)

只需将其添加到“ head”标签中即可。这样会根据设备宽度自动调整视频大小。

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
    video {
       width: 100%;
       height: auto;
    }
 </style>
 </head>