如何打印内联CSS样式? [英] How to print inline CSS styles?

查看:299
本文介绍了如何打印内联CSS样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有打印css样式的方法,即inline?

is there a way to print css styles, that are inline?

我使用此代码打印部分代码:

I use this code to print part of the code:

w=window.open();
w.document.write($('#printable').html());
w.print();
w.close();

我可以使用外部文件,使media = print,但html的一部分是chars是由php生成的,我可以通过为每个可能的结果做类,但这将是痛苦。

I could use external file and make it media=print, but part of the html are chars, that are generated by php and I could make it by making class for every posible outcome, but that would be pain.

任何想法?感谢。

推荐答案

查看演示: http://jsfiddle.net/rathoreahsan/x69UY/

如果您这样做,您认为如何:

What do you think if you do like this:

<div id="printableDiv">
    <style type="text/css">
        @media print {
            #printable { 
               color: red; 
               // Any Other style you want to add 
             }
        }
    </style>
    <div id="printable">
        This Text will print in red color.
    </div>
</div>

Javasript / Jqeury代码:

Javasript/Jqeury Code:

w=window.open();
w.document.write($('#printableDiv').html());
w.print();
w.close();

在这种情况下,一个弹出窗口打开并获取 printableDiv ,打印机的样式将包含在该弹出窗口中,因此打印机将从弹出窗口中读取样式并以此方式打印。

In this scenario while a popup opens and gets the HTML of printableDiv, the styles for printer will be included in that popup so the printer will read styles from popup and will print in that manner.

这篇关于如何打印内联CSS样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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