媒体查询无法正常运行

时间:2020-07-14 15:37:17

标签: css media-queries

我有一些CSS

.fullscreen-bg {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    overflow: hidden;
    z-index: -100;
}

.fullscreen-bg__video {
    position: absolute;
    top: 50%;
    left: 50%;
    width: auto;
    height: auto;
    min-height: 100%;
    -webkit-transform: translate(-50%, -50%);
       -moz-transform: translate(-50%, -50%);
        -ms-transform: translate(-50%, -50%);
        transform: translate(-50%, -50%);
}
@media (max-width: 767px) {
    .fullscreen-bg {
        background: url('../img/MichaelPR.jpg') center center / cover no-repeat;
    }

    .fullscreen-bg__video {
        display: none;
    }
}

HTML

<div className="fullscreen-bg"> 
    <video loop muted autoPlay className="fullscreen-bg__video"> 
        <source src={background} type="video/mp4" /> 
        <source src={background} type="video/ogg" /> 
        Your browser does not support the video tag. 
     </video> 
</div> 
<div> 
    <img className="logo" alt="Great State" src={logo} /> 
</div>

据我了解,仅当屏幕大于767时,才应有背景视频。背景视频始终显示。因此,这使我相信我所拥有的媒体查询无法正常运行。我尝试将默认背景设置为一种颜色,但现在仍然很幸运。仅当屏幕尺寸超出特定限制时,才能显示背景图像吗?

1 个答案:

答案 0 :(得分:0)

像这样替换您的媒体标签

@media all and (min-width : 320px) and (max-width : 767px) {...} 
or
@media only screen and (max-width: 767px)  {...}

并添加此元标记或将其替换为当前的

<meta content="width=device-width, initial-scale=1" name="viewport" />