通过打印机打印某些结果时,如何减小代码中的页面大小? [英] How to reduce the page size in the code when printing some results through printer ?

查看:118
本文介绍了通过打印机打印某些结果时,如何减小代码中的页面大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


如何通过减少代码中纸张的大小而不是在打印机选项中减少纸张的大小来打印一些文本?

Hi,
How can I print some text by reducing the size of the paper in the code rather than reducing it in printer options?

推荐答案

一种方法是准备特殊文本.文档/页面的打印机版本".但是,如今,通过锚点访问页面的单独版本被认为是不好的样式.除此以外,还可能会增加维护负担.这是因为存在一种更合适的现代方法:您可以定义CSS,该CSS为不同的媒体(在这种情况下,为内容的屏幕视图和sprinter视图)创建不同的布局和其他样式属性. >
这是一个非常合理,有用的功能,不仅是为了节省纸张和其他环境效益.对于简单的内容,这将毫无意义,但是对于更复杂的设计,这可能非常重要.查看带有一些按钮,列表框和其他控件的页面.谁需要这些印刷品?他们将无法在纸上单击它们.屏幕上的功能可能与印刷品有根本的不同.那么,如何使样式不同,以及如何隐藏一些不需要的元素并显示其他元素呢?

这是使用CSS中的媒体类型和@media规则完成的: http://www.w3.org/TR/CSS21/media.html [ ^ ].

基本上,您可以为您的CSS规则创建两个或三个分支,一些仅用于屏幕,一些仅用于打印机,某些用于两个.这是这样的:
One way to do so would be preparing special "printer version" of the document/page. But having a separate version of the page accessible via an anchor is considered bad style these days; besides it could be addition maintenance burden. And this is because there is a much more suitable, modern way of doing such things: you can define CSS which creates different layout and other style properties for different media, in this case, for screen and sprinter views at the content.

And this is a very reasonable, useful feature, not just for the sake of saving paper and other environmental benefits. For simple content, this would be pointless, but for more complicated designs it could be really important. Look at the page with some buttons, list boxes and other controls. Who need them in the print? They won''t be able to click them on the paper. On-screen features can be fundamentally different from the print. So, how to make the styles different, and also to hide some unwanted elements and show others?

This is done using Media Types and the @media rules in CSS: http://www.w3.org/TR/CSS21/media.html[^].

Basically, you can create two or three branches of your CSS rules, some only for screen, some only for printer, some for both. This is how:
@media print {
    /* rules for printer only */
}
@media screen {
    /* rules for screen only */
}
@media screen, print {
    /* rules for both screen and printer */
}


此外,您可以在浏览器中轻松调试此类样式表.您无需一直打印以进行测试;浏览器的打印预览将向您显示样式的效果.

—SA


Moreover, you can easily debug such stylesheet on the browser. You don''t need to print it all the time for testing; browser''s print preview will show you the effect of your styles.

—SA


这篇关于通过打印机打印某些结果时,如何减小代码中的页面大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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