CSS 媒体查询被忽略

标签 css media-queries

这段代码是我位置固定的网站菜单的一部分,它控制顶部的边距以防止与内容重叠。这取决于屏幕的宽度。但是,我不明白为什么 @media screen and (max-width: 329px) {} 条件被 @media screen and (max-width: 604px) 忽略和覆盖) {} 条件。 (仅供引用,它们表示固定菜单换行的断点,相应地需要将内容下推一行。)

现场演示:https://www.ashenglowgaming.com

@media screen and (max-width: 604px) {
  #menu-w-home-menu {
    line-height: 1.2em;
  }
  #main {
    margin-top: 89px !important;
  }
}

@media screen and (max-width: 329px) {
  #main {
    margin-top: 113px !important;
  }
  #menu-w-home-menu {
    line-height: 1.2em;
  }
}


/* For all larger screen sizes */

#main {
  margin-top: 66px;
}

#menu-w-home-menu {
  line-height: 1.2em;
}

最佳答案

这是因为您的 css 顺序。将您的普通 css 放在媒体查询上方,如下所示。它会很好地工作

#main {
  margin-top: 66px;
}

#menu-w-home-menu {
  line-height: 1.2em;
}

@media screen and (max-width: 604px) {
  #menu-w-home-menu {
    line-height: 1.2em;
  }
  #main {
    margin-top: 89px !important;
  }
}

@media screen and (max-width: 329px) {
  #main {
    margin-top: 113px !important;
  }
  #menu-w-home-menu {
    line-height: 1.2em;
  }
}

More help on to understand the order

希望对您有所帮助!

关于CSS 媒体查询被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48245618/

相关文章:

css - 完整日历默认 View

css - SASS 在多行上缩进语法?

html - 第 n 个 child (偶数/奇数)不工作和边界崩溃问题

javascript - 是否有可能以编程方式触发移动设备的 native 选择弹出窗口?

javascript - 如何将新闻收报机移动方向更改为从左到右

css - 导航栏的引导媒体查询不起作用

android - 如何创建适用于设备宽度和宽度的媒体查询

jquery - 同位素 - 砌体流体 columnWidth 和 gutter - 媒体查询

css - 我找不到调整媒体查询的高度

css - 悬停和取消悬停进入无限循环