Why website printed with Chrome is using mobile la

2019-06-23 05:32发布

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 and you will see in the preview that it's using the mobile layout (see image below).

The Verge printed with Chrome

While in Firefox, it uses around 900px (see image below).

enter image description here

Is there a way to make it print Desktop layout?

I know I can work around this by changing my mobile breakpoint to 568px, but I need my website to break in 768px for iPad.

2条回答
祖国的老花朵
2楼-- · 2019-06-23 05:47

Just add this to your style sheets

@media print {
  @page {
    size: 330mm 427mm;
    margin: 14mm;
  }
  .container {
    width: 1170px;
  }
}

I found answer from this link and its working perfectly... Bootstrap 3 Pages Printing Mobile Version

查看更多
对你真心纯属浪费
3楼-- · 2019-06-23 05:51

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:

<link href="..." media="print" rel="stylesheet" type="text/css">

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.

查看更多
登录 后发表回答