最初我有我的基础 CSS,然后我添加了一个 640 媒体查询...
@media screen and (max-width:640px) {}
我对所有内容进行了编码以适应移动设备,一切都很好。刚才我添加了另一个媒体查询...
@media screen and (max-width:840px) {}
现在,我网站的移动部分正在使用第二个媒体查询的代码?我不知道最大宽度这么大的手机。为什么 840 媒体查询会干扰我的移动媒体查询?
最佳答案
为了防止 CSS 被覆盖,使用下面的代码只为 640px
和 840px
之间的宽度指定规则:
@media screen and (min-width: 640px) and (max-width:840px) {
/* CSS rules for width between 640px and 840px */
}
或者您可以重新排序代码:
@media screen and (max-width:840px) {}
@media screen and (max-width:640px) {} /* This will override the above CSS rules */
查看此页面:MDN Media Queries学习一些好的做法。
关于html - 媒体查询问题 - 防止覆盖 CSS 规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32283073/