简体   繁体   English

如果一个媒体查询没有CSS格式,则html内容会捕获另一个媒体查询?

[英]If one media query dont have CSS formatting, html content catches another media query?

I'm trying to do my first project with media queries, and I'm facing a strange issue. 我正在尝试通过媒体查询来做我的第一个项目,但是我面临一个奇怪的问题。

I started to develop for mobile, using this media query: 我开始使用此媒体查询为手机开发:

@media screen and (max-width:479px)  {}

Then, I develop for larger mobile devices with: 然后,我为大型移动设备开发以下产品:

@media screen and (min-width:480px) and (max-width:600px) {}

Then for small tablets: 然后对于小平板电脑:

@media screen and (min-width:601px) and (max-width:720px) {}

And larger tablets: 和更大的平板电脑:

@media screen and (min-width:721px) and (max-width:980px)

Then for laptop: 然后用于笔记本电脑:

@media screen and (min-width:981px) {}

Everything works fine so far, but now I'm doing this media query @media screen and (min-width:1200px) {} for larger laptops, and when I resize the browser up to 1200, and If I don't have nothing inside this media query, my content rather than stay unformatted, what happens is that my content catches the previous media query: @media screen and (min-width:981px) {} . 到目前为止,一切正常,但现在我要对大型笔记本电脑进行@media screen and (min-width:1200px) {}媒体查询,并且当我将浏览器的大小调整为1200,并且如果我什么都没有时在此媒体查询中,我的内容而不是保持原格式,这是因为我的内容捕获了先前的媒体查询: @media screen and (min-width:981px) {}

Is this is normal?? 这是正常的吗? If one media query doesn't have CSS formatting, the content catches another media query? 如果一个媒体查询没有CSS格式,则内容捕获另一媒体查询?

If there is nothing inside a media query, then the browser doesn't need to change anything. 如果媒体查询中没有任何内容,则浏览器无需更改任何内容。

Since anything that is at least 1200px ( min-width:1200px ) is necessarily also at least 981px ( min-width:981px ), anything that applies in the latter will apply in the former if nothing is changed. 由于至少1200px( min-width:1200px )的任何内容也必须至少为981px( min-width:981px ),因此,如果不进行任何更改,则适用于后者的任何内容都将适用于前者。 In a way, you could say that the browser "catches" the earlier media query, but it really is catching both ; 从某种意义上讲,您可以说浏览器“捕获”了较早的媒体查询,但是它确实捕获了这两个媒体查询。 there is just nothing in the second to override the first so the styles remain the same. 第二个中没有什么东西可以覆盖第一个,因此样式保持不变。

This is expected behavior. 这是预期的行为。

The reason why your mobile and tablet media queries don't apply on laptops (and desktops) is because you have specified max-width , unlike your laptop media query, which only has a min-width condition. 为什么你的手机和平板电脑的媒体查询上的笔记本电脑(和台式机)应用的原因是因为您指定max-width ,不像你的笔记本电脑媒体查询,其中只有一个min-width条件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM