css - 不同大小的多个媒体查询不起作用

标签 css media-queries

我目前正在努力使我的网站具有响应能力,并且能够通过使用以下媒体查询来响应中/大型表大小:

@media (max-width: 1280px) {
    .nav-tab {
        display: none;
    }

    .nav-drawer-button {
        display: block;
        float: left;
        padding-top: 30px;
        margin-left: 80%;
        cursor: pointer;
    }

    .panel-title {
        width: 40%;
        font-size: 24px;
    }

    .panel-text {
        width: 70%;
    }

    .footer-text {
        padding-top: 15px;
    }

    .social:first-child {
        margin-right: 1em;
    }
}

尺寸为 600px - 650px 的屏幕上存在问题,因此我在该查询之后创建了另一个查询,如下所示:

@media (min-width: 600px) and (max-width: 650px) {
    .nav-drawer-button {
        margin-left: 70%;
    }
}

这似乎不起作用。它应用第一个媒体查询。我尝试更改查询的顺序,但没有成功。我做错了什么?

这是整个 CSS:

@import url(http://fonts.googleapis.com/css?family=Roboto:500);
@import url(http://fonts.googleapis.com/css?family=Open+Sans);

body {
    margin: 0;
    background-color: #eeeeee;
}

footer {
    margin: 0;
    height: 3em;
    background-color: #333333;
    /*border-top: 3px solid #338a6c;*/
}

.navbar {
    height: 6em;
    margin: 0;
    background-color: #333333;
    border-bottom: 5px solid #338a6c;
    box-shadow: 2px 2px 5px #333333;
    list-style: none;
}

.nav-drawer-button {
    display: none;
}

.nav-drawer {
    display: none;
}

.nav-tab {
    height: 100%;
    float: left;
    color: #eeeeee;
    padding-left: 2em;
    padding-right: 2em;
    text-align: center;
    font-family: "Open Sans", sans-serif;
}

.nav-tab:nth-child(2) {
    margin-left: 55%;
}

.nav-tab:hover {
    border-left: 1px solid #555555;
    border-right: 1px solid #555555;
    background-color: rgba(85, 85, 85, .3);
    cursor: pointer;
}
.nav-logo {
    margin-left: 1em;
    padding-top: 25px;
    float: left;
}

.nav-logo:hover {
    cursor: pointer;
}

.nav-text {
    padding-top: 5px;
}

.bg {
    fill-opacity: 0.1;
    background-attachment: fixed;
    background-repeat: no-repeat;
    background-size: cover;
    width: 100%;
    height: 500px;
    text-align: center;
}

.bg-1 {
    background-image: url("../img/para1.jpg");
}

.bg-2 {
    background-image: url("../img/para2.jpg");
}

.bg-3 {
    background-image: url("../img/para3.jpg");
    height: 300px;
}

.bg-text {

    margin: 0;
    padding-top: 250px;
    font-family: "Roboto", sans-serif;
    font-size: 36pt;
    color: #eeeeee;
    text-shadow: 2px 2px 2px #222222;
}

.bg-3>.bg-text {
    padding-top: 150px;
}

.fg {
    border-top: 3px solid #338a6c;
    border-bottom: 3px solid #338a6c;
    background-color: #eeeeee;
    width: 100%;
    height: 610px;
}

.panel-title {
    width: 20%;
    color: #222222;
    font-family: "Roboto", sans-serif;
    font-size: 36px;
    border-bottom: 3px solid #aaaaaa;
    margin-left: auto;
    margin-right: auto;
    margin-bottom: 1em;
    padding-left: auto;
    padding-right: auto;
    padding-top: 0.5em;
    padding-bottom: 20px;
    text-align: center;
}

.panel-text {
    /* SEE: util.js */
    /*opacity: 0;*/
    width: 50%;
    color: #333333;
    font-family: "Open Sans", sans-serif;
    font-size: 16px;
    font-weight: 500;
    margin-left: auto;
    margin-right: auto;
    text-align: justify;
}

.button {
    width: 8em;
    height: 2em;
    font-size: 16pt;
    font-family: "Roboto", sans-serif;
    text-align: center;
    padding-top: 1em;
    margin-top: 3em;
    margin-left: auto;
    margin-right: auto;
    border: 2px solid #338a6c;
    border-radius: 5px;
    background-color: transparent;
    color: #338a6c;
}

.button:hover {
    border: 2px solid #338a6c;
    background-color: #338a6c;
    color: #eeeeee;
    cursor: pointer;
}

.gap {
    margin-left: 5px;
}

.social-icons {
    height: 100%;
    list-style: none;
    margin: 0;
}

.social {
    float: right;
    font-size: 14pt;
    color: #eeeeee;
    height: 68%;
    width: 3em;
    padding-top: 15px;
    padding-bottom: 0;
    text-align: center;
}

.social:hover {
    border-left: 1px solid #555555;
    border-right: 1px solid #555555;
    color: #338a6c;
    background-color: rgba(85, 85, 85, .3);
    cursor: pointer;
}

.social:first-child {
    margin-right: 4em;
}

.footer-text {
    margin: 0;
    float: left;
    font-size: 10pt;
    font-family: "Open-Sans", sans-serif;
    color: #eeeeee;
    width: 20em;
    text-align: center;
    padding-top: 20px;
}

.footer-gap {
    border-top: 5px solid #338a6c;
    background-color: #eeeeee;
    height: 0.3em;
}

/* Small Tablet / Phablet */
@media (min-width: 600px) and (max-width: 600px) {
    .nav-drawer-button {
        margin-left: 10%;
    }
}

/* Tablet Stuffz */
@media (max-width: 1280px) {
    .nav-tab {
        display: none;
    }

    .nav-drawer-button {
        display: block;
        float: left;
        padding-top: 30px;
        margin-left: 80%;
        cursor: pointer;
    }

    .panel-title {
        width: 40%;
        font-size: 24px;
    }

    .panel-text {
        width: 70%;
    }

    .footer-text {
        padding-top: 15px;
    }

    .social:first-child {
        margin-right: 1em;
    }
}

最佳答案

首先,您的 HTML 需要有 viewport设置在 <head>部分。

下一步 - 您将针对最大宽度为 1280 像素(即 1280 像素或更小的屏幕)应用所有第一个媒体查询。使用@media screen (max-width: 651px) and (min-width:1280px)反而。

对于较小的屏幕尺寸,您的代码似乎是正确的。

编辑

只有当多个查询应用于同一屏幕设置时,该顺序才会对显示产生影响。通常从最大的屏幕设置开始,然后逐渐减小到最小的屏幕设置,这样每次只反射(reflect)额外的更改,而不是在每个媒体查询中包含每个更改。

关于css - 不同大小的多个媒体查询不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32041430/

相关文章:

javascript - JQuery 自动完成出现在 JQuery 菜单后面

Css 选项宽度错误

javascript - 设置隐藏元素的宽度和高度

css - 在顺序媒体查询中使用最大宽度和最小宽度的优点?

html - 针对 1024px 但在桌面和平板电脑上显示不同的媒体查询?可能的?

javascript - 当词缀 div 大于内容和窗口时词缀 Bootstrap 出现问题

html - Flexbox 流体水平滚动

html - 制作一个屏幕宽度一定的div元素 "think"?

html - 内容在 480px 媒体查询上重叠

iphone - 在 Iphone4 和 5 模拟器中缩放/放大背景?使用纯 HTML5 和 CSS3 代码