问题描述
我有一个表格作为 HTML 文档的全部内容(出于合法的表格目的...它是表格数据,而不是用于布局).某些单元格指定了宽度和高度(不是通过 css,而是在表格结构中使用旧的内联大小调整),但整个表格没有指定宽度或高度.这是一个相当大的表格,但如果缩放比例适当(大约 70%),它可以打印在一张纸上.这可以通过在 IE、Firefox 和 Chrome 的打印机设置中使用 scale page
功能来完成.有没有办法将整个页面(在我的情况下只是这个表)作为打印样式表的一部分(我知道 @media print {}
但那里的语句被忽略了...问题在于适当的缩放命令,而不是设置打印 css)?我可以用这个缩放屏幕视图:
I have a table as the entire content of an HTML document (for legitimate table purposes...it is table data, not for layout). Some cells have widths and heights specified (not through css but using the old sizing inline in a table structure), but the overall table does not have a width or height specified. This is a fairly large table, but with proper scaling (about 70%) it can be printed to fit nicely on a single sheet of paper. This can be accomplished by using the scale page
function within the printer settings of IE, Firefox, and Chrome. Is there a way to scale the whole page (which in my case is just this table) as part of a print stylesheet (I know about @media print {}
but the statements there are being ignored...the issue is with proper commands for scaling, not with setting up the print css)? I can scale the on-screen view with this:
body {
transform: scale(.7);
}
然而,在打印时,Chrome(和其他人)会忽略我的比例并自动缩放表格以适应纸张的宽度,这导致我的表格被拆分到第二页.我也尝试应用此方法但没有成功:
however when printing, Chrome (and others) disregard my scale and automatically scale the table to fit the width of the paper and that results in my table being split onto a second page. I have tried applying this as well with no success:
table {page-break-inside: avoid;}
推荐答案
我最终重写了整个表格,将百分比大小作为类应用,然后能够缩放页面以进行打印.不知道为什么浏览器会忽略我关于转换的打印样式,但是将表格从固定大小转换为比例大小使我能够使用 CSS 对其进行缩放并且问题消失了.
I ended up rewriting the whole table with percentage sizes applied as classes and then was able to scale the page for printing. Not sure why the browser was ignoring my print styles regarding the transform but converting the table from fixed sizes to proportional sizes has enabled me to scale it with CSS and the issue is gone.
这篇关于在使用 css 打印之前缩放 html 表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!