html - 媒体查询设置

标签 html css media-queries tablet

我为手机创建了一个媒体查询

@media screen and (max-device-width: 480px), screen and (max-width: 480px)  {  ...css here... body {width:50%;}

但我需要这个桌面查询

@media screen and (max-device-width: 750px), screen and (max-width: 750px)  

如果我将喜欢添加到 @media 桌面查询 .body {width:100%;} 设置也会更改为 480px。

我的问题是:如何将 480px css 设置与 750px css 设置分开

最佳答案

方法一:

先写大宽度的查询,再写小宽度的查询,这样它们就可以覆盖它们

@media screen and (max-width: 750px){
  body{
    width:100%;
  }
}
@media screen and (max-width: 480px){
  body{
    width:50%;
  }
}

方法二:

同时定义最小宽度:

@media screen and (max-width: 750px) and (min-width: 481px){
  body{
    width:100%;
  }
}
@media screen and (max-width: 480px){
  body{
    width:50%;
  }
}

注意:我认为您不需要同时使用 max-device-widthmax-width

关于html - 媒体查询设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35079229/

相关文章:

javascript - 要标记的下拉列表元素

javascript - html 和 javascript 中的生活游戏不起作用

css - 为什么无法更改 css 中的内容?

css - 不同大小的浏览器的不同 css 样式

css - Bootstrap Firefox on Mac 媒体查询断点

html - 试图使图片可缩放,但大小相同

php - Wordpress 插件最大帖子

javascript - 无法在 for 循环中设置超时

Css 剪辑路径之间没有间隙

ipad - 最小宽度媒体查询在 ipad 上不起作用?