How to make print use desktop media queries?

爱⌒轻易说出口 提交于 2019-12-31 05:59:10

问题


I am attempting to add some print functionality to my page, but I am having an issue where when I print, it is printing as if it is mobile. How can I make it so that when someone hits print it prints the desktop version?

$('.print-btn').click(function(e) {
  window.print();
});
.visible-desktop {
  display:none;
}

@media only screen and (min-width:768px) {
  .visible-desktop {
    display:block;
  }
  
  .visible-mobile {
    display:none;
  }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
  <div class="visible-desktop">Viewing from desktop</div>
  <div class="visible-mobile">Viewing from mobile</div>
</div>

<a class="print-btn" href="#">Pring</a>

回答1:


You can add an @media print rule at the bottom of your stylesheet:

@media print {
  .visible-desktop {
    display:block;
  }
  .visible-mobile {
    display:none;
  }
}



回答2:


only screen

This excludes print. If you want to include print, don't write that.




回答3:


You should pick one state (probably desktop) and make it the "default", by moving that state outside media queries.

The other states should override the default state's properties in media queries.



来源:https://stackoverflow.com/questions/46472259/how-to-make-print-use-desktop-media-queries

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!