CSS 媒体查询和屏幕分辨率

标签 css media-queries

我试图让这些列在这些条件下模糊显示:

  1. 在打电话时 -- 显示一列(100%)
  2. 在平板电脑上 - 显示两列(占 50%)
  3. 在桌面上时——尽可能多地显示

到目前为止,这是我的 CSS 代码,但它没有按预期工作:

编辑:我稍微修改了媒体查询,背景颜色按预期改变了……但宽度没有。重新迭代...在小型设备上我希望 DIV 占据 100% 的屏幕宽度...在平板电脑上我希望它们将屏幕分成两半...在桌面屏幕上我希望它们分布在整个宽度上相应的屏幕。

  @media screen and (max-width: 35.5em) { /* 568px or less */
    div.listing {
      -moz-columns: 100%;
      -webkit-columns: 100%;
      columns: 100%;
      background-color: red;
    }
  }

  @media screen and (min-width: 35.5em) and (max-width: 48em) { /* 568px - 768px */
    div.listing {
      -moz-columns: 50%;
      -webkit-columns: 50%;
      columns: 50%;
      background-color: orange;
    }
  }

  @media screen and (min-width: 48em) { /* 1024px */
    div.listing {
      -moz-columns: 350px;
      -webkit-columns: 350px;
      columns: 350px;
      background-color: green;
    }
  }      

最佳答案

实际上,您的 完全按预期工作。查看规范:http://www.w3.org/TR/css3-multicol/#the-number-and-width-of-columns

问题在于 column-width最小 宽度。如果您将列设置为 50%,该列将始终默认为 100%,因为无论如何,该列将始终至少占其容器的一半(我可能解释得很奇怪)。您基本上需要为平板电脑 View 设置所需的 em 或 px 大小。或者,正如 Adriano66 指出的那样,设置列数,而不是宽度。

@media screen and (max-width: 35.5em) { /* 568px or less */
    div.listing {
      -moz-columns: 100%;
      -webkit-columns: 100%;
      columns: 100%;
      background-color: red;
    }
  }

  @media screen and (min-width: 35.5em) and (max-width: 48em) { /* 568px - 768px */
    div.listing {
      -moz-columns: 2;
      -webkit-columns:2;
      columns: 2;
      background-color: orange;
    }
  }

  @media screen and (min-width: 48em) { /* 1024px */
    div.listing {
      -moz-columns: 350px;
      -webkit-columns: 350px;
      columns: 350px;
      background-color: green;
    }
  }   

fiddle : http://jsfiddle.net/disinfor/a65pb9re/1/

关于CSS 媒体查询和屏幕分辨率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26633573/

相关文章:

jquery - 缩放后 svg 过滤器在 mozilla firefox 中不起作用

jquery - 检查 CSS 位置后如何解决 Safari 9.1 转换剪辑路径的问题?

html - 将鼠标悬停在 li 元素上并对子 img 做一些事情

css - 具有默认样式的媒体查询无法按预期工作

html - css 媒体查询更改

javascript - 如何在 div 上保持 16/9 的纵横比而不让它溢出到容器外?

javascript - 仅使用位置隐藏右侧边栏

css - 媒体查询冲突

Android 布局 - 图像似乎被隐藏

javascript - CSS 媒体查询和 jQuery 窗口 .width() 不匹配