当我要打印文本时,我如何调整它的字体大小?我试图放置字体大小属性,但当我要单击“打印”按钮时,它不会使用,它只会返回到默认的字体大小。
function print1(strid)
{
var values = document.getElementById(strid);
var printing =window.open("");
printing.document.write(values.innerHTML);
printing.document.close();
printing.focus();
printing.print();
printing.close();
}
<div id="print2">
Ex : My data table 1
</div>
<input type="button" value="Print" onclick="return print1('print2')">发布于 2016-04-11 01:18:11
您可以使用CSS媒体查询。在样式部分中,添加如下内容,以增加整个正文的字体大小。您可以使用任何其他CSS选择器,而不是body,因此对于div,只使用#print2 2。
<style type="text/css">
@media print {
body {
font-size: large;
}
}
</style>将其添加到<head>标记之后的HTML文档中。当然,您可以在块中设置任何其他CSS属性。
下面是一个完整的例子:
<!doctype html>
<html>
<head>
<style type="text/css">
body {
font-family: "Gill Sans", "Gill Sans MT", "Myriad Pro", "DejaVu Sans Condensed", Helvetica, Arial, sans-serif;
font-size: 12pt;
}
@media print {
body {
font-size: 48pt;
}
}
</style>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>
<body>
This is a sample document with normal size text that should print large.
</body>
</html>https://stackoverflow.com/questions/36538317
复制相似问题