媒体查询取消其他媒体查询 [英] Media query canceling other media queries

查看:255
本文介绍了媒体查询取消其他媒体查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑,因为如果宽度小于748px,标志应该被隐藏。

I'm confused because the logo should be hidden if width is less than 748px. However all sizes below 960px width show the logo.

这里缺少什么?

推荐答案

(在屏幕截图中)我看到 max-width:768px 媒体查询在 max-width:960px 之前声明为,这是不正确的。仅使用 max-width 的媒体查询应按降序排序。让我们假设您以此顺序声明媒体查询:

(In the screenshot of the screen) I see that the max-width: 768px media query is declared before max-width: 960px which is incorrect. Media queries that only use max-width should be sorted descending. Let us assume that you declare media queries in this order:


  1. (max-width:768px)

  2. (max-width:960px)

  1. (max-width: 768px)
  2. (max-width: 960px)

如果你的屏幕是400px宽,那么两个媒体查询将匹配条件。

If your screen is 400px wide then both media queries will match the condition. In this case the media query block declared later wins.

解决方案:

排序您的最大宽度规则递减

Sort your max-width rules descending (larger widths first).

或使用互斥媒体查询块,例如:

Or use mutually exclusive media query blocks such as this:


  • (min-width:961px)

  • (min-width:769px)and max-width:960px)

  • (max-width:768px)

  • (min-width: 961px)
  • (min-width: 769px) and (max-width: 960px)
  • (max-width: 768px)

在这种情况下,顺序无关紧要。

In this case order does not matter.

这篇关于媒体查询取消其他媒体查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆