我创建了要从浏览器打印的简单页面。 我把我能找到的所有口哨放在我的标题和图片的中心。
<html>
<head>
<link rel="stylesheet" href="print.css" type="text/css" media="print" />
<!-- print.css is empty -->
</head>
<body style="text-align: center; margin: 0 auto;">
<div>
<div style="font-size:48pt">
Pretty Long-Long-Long Title
</div>
<img src="content/images/sample.jpg" style="width:80%"/>
</div>
</body>
</html>
该页面在所有浏览器中看起来都很好并且居中。
该页面在 IE 和 Firefox 中打印良好(居中),但在 Chrome 中整个主体框是左对齐的并且比页面宽度小得多。
是否有任何有助于从 Chrome 打印居中标题/图像的口哨声?
问题解决了。
问题出在 Chrome 本身。更确切地说,在使用 Chrome PDF Writer 插件的打印预览中。 Chrome PDF Writer 似乎无法识别页面大小并且没有任何页面设置设置。我禁用了 Chrome 的打印预览,安装了 Adobe 的 PDF 打印机,使用我的原始代码片段打印一切正常。
最佳答案
试试这个
<body>
<div align="center" style="text-align:center;">
<div style="font-size:48pt">
Pretty Long-Long-Long Title
</div>
<img src="content/images/sample.jpg" style="width:80%"/>
</div>
</body>
要么
<div align="center" style="text-align:center;">
或
<div style="text-align:center;margin:0 auto;">
在 chrome 中为我工作,打印成 pdf
关于html - 从 Chrome 打印出来的内容不居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6311036/