Why website printed with Chrome is using mobile layout?

后端 未结 2 1930
借酒劲吻你
借酒劲吻你 2021-01-17 20:39

In Chrome, when printing to A4 paper, it is rendered with 568px media query width.

Try printing a responsive website such as The Verge or Bootstrap

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-17 21:12

    The Verge isn't using a mobile layout for printing. It's using its own print layout. If you inspect the page whilst emulating a media of print you'll see a load of media="print" declarations. This is loaded in through the HTML:

    
    

    If you want a website to look different when printing than it does on mobile, simply specify screen within your mobile media queries:

    @media screen and (max-width: 768px) {
        ...
    }
    

    When printing, the screen declaration will be ignored, thus completely ignoring your mobile media query.

提交回复
热议问题