Javascript 如何控制打印字体大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32429832/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to control print font size
提问by mseifert
I am allowing my users to print but the output is way too large (I have to manually adjust to about 60% in the print dialog). I use a css media query (below) to control the content and have tried changing the font-size of the html, body{}
without any change to the output font size. Printing to Adobe PDF prints correctly
我允许我的用户打印但输出太大(我必须在打印对话框中手动调整到大约 60%)。我使用 css 媒体查询(如下)来控制内容,并尝试更改 的字体大小html, body{}
而不更改输出字体大小。打印到 Adobe PDF 可以正确打印
Any ideas what I am doing wrong?
任何想法我做错了什么?
My Print Link:
我的打印链接:
<a href="#" onclick="window.print(); return false;"></a>
My css:
我的CSS:
@media print {
body * {
visibility: hidden;
}
.printme, .printme * {
visibility: visible;
}
.printme {
position: absolute;
left: 0;
top: 0;
}
.printme, .printme:last-child {
page-break-after: avoid;
}
.display-none-on, .display-none-on * {
display: none !important;
}
html, body {
height: auto;
font-size: 12pt; /* changing to 10pt has no impact */
}
}
采纳答案by mseifert
Finally figured this out and there were multiple causes. The main thing is that I needed to also set the font-size for the div that contained the text. In the main css, I have body font-size set to 62.5% and the div font-size set to 130%. When I set the body font-size for @media print{} to 12pt, it continued to use the 130% div setting and so printed very large.
终于想通了,这有多种原因。最重要的是,我还需要为包含文本的 div 设置字体大小。在主 css 中,我将 body font-size 设置为 62.5%,将 div font-size 设置为 130%。当我将 @media print{} 的正文字体大小设置为 12pt 时,它继续使用 130% div 设置,因此打印的非常大。
I believe my efforts to adjust the font-size via changing the body font-size were flawed because I minify my css and probably forgot to minify after each change.
我相信我通过更改正文字体大小来调整字体大小的努力是有缺陷的,因为我缩小了我的 css 并且可能在每次更改后都忘记了缩小。