有没有办法让媒体打印CSS的正常观点? [英] Is there a way to enable media print css to a normal view?

查看:105
本文介绍了有没有办法让媒体打印CSS的正常观点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个包含大量打印媒体查询的网站,以在打印页面时调整内容。当您转到Web浏览器的打印模式时,查询效果很好。但我想在常规网页上应用/删除 @media print 查询,而无需进入打印模式(通过单击按钮)是否有任何方法可以实现这个?

I developed a website with a bunch of print media queries to align stuff when printing the page. when you go to the print mode on web browser, the queries works great. but i want apply/remove those @media print queries on a regular web page without having to go into the printing mode.(by clicking a button) is there any way to achieve this?

推荐答案

添加到yezzz的答案:如果您的HTML中链接了打印CSS,如

To add to yezzz's answer: If you have the print CSS linked in the HTML like

<link rel="stylesheet" media="print" href="...">

您可以移除媒体属性以启用无论是在服务器上还是使用Javascript:

you can remove the media attribute to enable those styles everywhere, either on the server or with Javascript:

document.querySelector('[media="print"]').removeAttribute('media');

请注意,如果打印样式表中的语句被封装在 @media print {} 规则。

Note, that this doesn't work, if the statements in the print stylesheet are wrapped in a @media print {} rule.

这篇关于有没有办法让媒体打印CSS的正常观点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆