简体   繁体   English

我如何按原样打印页面

[英]How can i print the page as it is

I'd have added a button in my page include onsubmit="return window.print()" but when i click on it, A print window dialog appears in printing view my page colors turns black all styles gone. 我在页面上添加了一个按钮,其中包括onsubmit="return window.print()"但是当我单击它时,在打印视图中出现一个打印窗口对话框,我的页面颜色变为黑色,所有样式消失了。 How can i print the page as it is with style with same colors 如何打印具有相同颜色的样式的页面

It happens when your css is not optimized for print media. 如果您的CSS没有针对打印介质进行优化,则会发生这种情况。 You can include your css in below style. 您可以在以下样式中包含CSS。

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

And remember that background images not rendered in print. 并请记住,背景图像未打印出来。

Reference article : http://www.smashingmagazine.com/2011/11/24/how-to-set-up-a-print-style-sheet/ 参考文章: http : //www.smashingmagazine.com/2011/11/24/how-to-set-up-a-print-style-sheet/

Use the @media print to style your pages for printing. 使用@media print来设置页面样式以进行打印。

Example in CSS file: CSS文件中的示例:

@media print {//styles
}

Also here is a link to a starter guide of this: http://www.smashingmagazine.com/2011/11/24/how-to-set-up-a-print-style-sheet/ 另外,这里还有一个入门指南的链接: http : //www.smashingmagazine.com/2011/11/24/how-to-set-up-a-print-style-sheet/

Hope that helps. 希望能有所帮助。

Link a stylesheet at the bottom of your head (So that it is the primary one). 在您的底部链接一个样式表(这样它就是主要样式表)。

In that stylesheet put in the following media query 在该样式表中,输入以下媒体查询

@media print
{
    put styles here
}

Whatever you put in the query will be used in printing. 您在查询中输入的任何内容都将用于打印。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM