【问题标题】:Media Queries aren't working for smaller sizes媒体查询不适用于较小的尺寸
【发布时间】:2018-04-18 21:41:15
【问题描述】:

页面上的元素只响应 1650px 及以上屏幕尺寸的媒体查询。结果,我无法使项目响应移动设备。台式机上的一切都很好,但平板电脑和手机屏幕没有响应。在下面发布代码。某处有错误吗?这是我的媒体查询:

 @media only screen and (max-width: 380px) {
    footer {
        margin-top: 50px;
    }
    .header-image {
        height: 50px;
    }
    #social-icons {
        display: flex;
    }
}
@media only screen and (max-width: 480px) {
    .header-image {
        height: 100px;
    }
    #social-icons {
        display: flex;
    }
    .custom-logo {
        margin-top: 50px;
    }
}
@media only screen and (max-width: 600px) {
    footer {
        margin-bottom: 50px;
        text-align: center;
        margin: 0 auto;
    }
    #social-icons {
        display: flex;
    }
    .textwidget {
        display: flex;
        text-align: center;
    }
    .widget_text {
        margin-right: 60px;
    }
    .custom-logo {
        margin: 30px;
    }
}
@media only screen and (max-width: 768px) {
    .header-image {
        height: 100px;
    }
    .menu-toggle {
        display: none;
    }
    .custom-logo {
        width: 50%;
        margin-top: -20px;
    }
}
@media only screen and (max-width: 900px) {
    .main-navigation ul li a {
        font-size: 16px;
        display: none;
    }
    .custom-logo {
        width: 70%;
        position: relative;
    }
}
@media only screen and (max-width: 1100px) {
    .main-navigation ul {
        margin-top: -35px;
    }
    .custom-logo {
        width: 50%;
        margin-top: -20px;
        position: relative;
    }
}
@media only screen and (max-width: 1250px) {
    .custom-logo {
        margin-left: 30px;
    }
}
@media only screen and (max-width: 1400px) {
    .custom-logo {
        margin-top: 50px;
        width: 50%;
    }
}
@media only screen and (max-width: 1500px) {
    .custom-logo {
        margin-left: 100px;
    }
}
@media only screen and (max-width: 1650px) {
    .custom-logo {
        margin: 0px;
    }
}
@media only screen and (max-width: 1850px) {
    .custom-logo {
        width: 25%;
    }
}

【问题讨论】:

  • 请同时发布 HTML。
  • 正如在答案中发布的那样,样式表下方的查询将覆盖上面的查询。颠倒顺序,使较低的max-width 低于具有较高值的​​max-width

标签: css mobile responsive-design media-queries


【解决方案1】:

当使用非移动优先方法 (max-width) 时,您需要将查询按从高到低的顺序排列(因为 CSS 是级联的,所以最新的规则将覆盖第一个规则),但你有它倒退。

【讨论】:

    猜你喜欢
    • 2020-04-26
    • 2019-12-10
    • 2016-01-30
    • 2021-12-17
    • 1970-01-01
    • 2015-03-16
    • 2017-03-19
    • 1970-01-01
    • 2018-09-11
    相关资源
    最近更新 更多