css - 结合 CSS 媒体查询

标签 css media-queries

我想向打印页面 (media=print) 的人和在手机上浏览的人显示同一组 CSS 样式。有什么方法可以组合 CSS 媒体查询吗?

有点像

@media only print or @media only screen and (max-device-width: 480px) {
  #container {
    width: 480px;
  }
} 

最佳答案

用逗号分隔:

@media only print, only screen and (max-device-width: 480px)

See the spec ,特别是示例 VI(添加了重点):

Several media queries can be combined in a media query list. A comma-separated list of media queries. If one or more of the media queries in the comma-separated list are true, the whole list is true, and otherwise false. In the media queries syntax, the comma expresses a logical OR, while the ‘and’ keyword expresses a logical AND.

我怀疑是否需要第二个 only,因此您可以这样做:

@media only print, screen and (max-device-width: 480px)

关于css - 结合 CSS 媒体查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8994664/

相关文章:

html - 限制文本框中显示的行数,但不限制用户写入

css - 位置绝对元素可见内部溢出 :hidden element

javascript - TD 不响应 Outlook

html - 为什么这些不能在移动浏览器上正确缩放?

javascript - 导出 <SVG> 时文件损坏

javascript - 响应重叠图像与 css/js

html - 媒体查询无响应

css - 推特 Bootstrap 子导航改变颜色

css - '@media only ' and ' @media all' 区别

html - 浏览器不同缩放级别的媒体查询