打印/预览忽略我的Print.css [英] Print/Preview Ignoring my Print.css

查看:171
本文介绍了打印/预览忽略我的Print.css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个令我头痛的问题。我正在尝试打印报告并使用print.css正确格式化,但它完全忽略了我的css每次。有人有这个问题吗?我确保CSS文件在正确的目录等,但仍然没有运气。



这是我的模板:



注意:我使用javascript来控制打印按钮,而javascript里面包含了CSS链接。我也试过把它放在HTML页面上,但没有帮助。

  ... 
< script type =text / javascript>

function printContent(id){

str = document.getElementById(id).innerHTML
newwin = window.open('','printwin',' left = 100,top = 100,'+
'width = 900,height = 400,scrollbars = 1')
newwin.document.write('< HTML> \\\
< HEAD& \\ n')
newwin.document.write('< TITLE>打印页面< / TITLE> \\\
')
newwin.document.write('< link rel =stylesheet =text / css'+
'href =/ media / css / print.cssmedia =print/> \\\
')
newwin.document.write('< ; script> \\\
')
...

使用Ubuntu 10.10和Firefox 7.如果这有帮助。



修改



我安装了Firefox开发工具栏。它允许您将页面查看为不同的媒体。现在当我点击打印时,它会显示所有的样式更改,但是当我打印时,它不遵循。

解决方案

 < HTML> 
< head>
< title>您的网站标题< / title>
< link rel =stylesheetmedia =screenhref =/ media / css / mainStyle.csstype =text / css>
< link rel =stylesheetmedia =printhref =/ media / css / print.csstype =text / css>
< / head>
< body>
< input type =buttonvalue =PrintonClick =javascript:window.print(); />
< / body>
< / html>

也许你可能想去上面的HTML模板,看看是否适合你或适合你的需要。



在我看来,您提出的功能实际上更好的是在服务器端而不是客户端使用javascript编写,因为您正在尝试动态生成HTML页面那里。您可以将该页面输出为print.html或某些东西,一旦发送到客户端,您可以应用print.css样式并进行打印。无论如何,这里只是一些想法,希望它有助于你的情况。干杯。


I have an issue thats causing me some headaches. I'm trying to print a report and format it correctly with a print.css but it completely ignores my css everytime. Has anyone had this issue before? I made sure the CSS file is in the correct directory, etc but still no luck.

Here is my template:

Note: I use javascript to control the print button and inside the javascript is where I have included the CSS link. I have also tried putting it just on the HTML page but that didn't help.

...
<script type="text/javascript">

function printContent(id){

   str=document.getElementById(id).innerHTML
   newwin=window.open('','printwin','left=100,top=100,'+
                         'width=900,height=400, scrollbars=1')
   newwin.document.write('<HTML>\n<HEAD>\n')
   newwin.document.write('<TITLE>Print Page</TITLE>\n')
   newwin.document.write('<link rel="stylesheet" type="text/css" '+
                         'href="/media/css/print.css" media="print"/>\n')
   newwin.document.write('<script>\n')
   ...

Now for this project I am using Ubuntu 10.10, and Firefox 7. If that helps at all.

Edit

I installed the web developer toolbar for firefox. It allows you to view the page as different medias. Now when I click print, it shows all my style changes, but when I print, it doesn't follow them.

解决方案

<html>
    <head>
        <title>your website title</title>
        <link rel="stylesheet" media="screen" href="/media/css/mainStyle.css" type="text/css">
        <link rel="stylesheet" media="print" href="/media/css/print.css" type="text/css">
    </head>
    <body>
        <input type="button" value="Print" onClick="javascript:window.print();" />
    </body>
</html>

Maybe you might wanna give above HTML template a go, and see if that works for you or suits your needs.

In my opinion, your proposed function is actually better to be written on the server side rather than the client side with javascript, as you are trying to dynamically generate html page in there. You can output that page as print.html or something, and once it gets sent to the client, you then apply the print.css style and do the printing. Anyway, just a few ideas here, hopefully it helps a bit in your case. Cheers.

这篇关于打印/预览忽略我的Print.css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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