Combining CSS media queries

前端 未结 2 1993
庸人自扰
庸人自扰 2020-12-08 18:50

I want to display the same set of CSS styles to people printing the page (media=print) and people browsing on a mobile phone. Is there a way I can combine CSS media queries?

2条回答
  •  伪装坚强ぢ
    2020-12-08 19:11

    Separate them with a comma:

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

    See the spec, in particular, example VI (emphasis added):

    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.

    I doubt that the second only is needed, so you can probably do:

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

提交回复
热议问题