Chrome似乎错误地计算了打印时以毫米为单位的css大小 [英] Chrome seems to miscalculate css sizes given in mm unit when printing

查看:80
本文介绍了Chrome似乎错误地计算了打印时以毫米为单位的css大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用CSS打印到A4.

I want to print to A4 using css.

A4高297毫米-顶部边距6毫米-底部边距6毫米=内容应保留285毫米.

A4 is 297mm high - 6 mm margin top - 6 mm margin bottom = 285 mm should be left for content.

在IE 11中:我必须将页面边框设置为6毫米并禁用页眉/页脚->当我将内容高度设置为284毫米(1毫米差异对我来说足够近)时,文本将出现在应该出现的位置

In IE 11 : I have to set page borders to 6 mm and disable header/footer --> Text appears where it should when I set content height to 284 mm (1 mm diff is close enough for me)

在Chrome 33中:我不必更改任何设置->文本位于远低于其应有的位置的位置.仅当我将内容高度设置为267 mm时才起作用(18 mm差异在哪里去了?)

In Chrome 33: I don't have to change any settings --> Text is located far below from where it should be. It only works when I set content height to 267 mm (where did 18 mm diff go?)

<!DOCTYPE html>
<html>
   <head>
      <style type="text/css">
         @page {
            margin: 6mm;
            size: A4 portrait;
         }
         body {
            margin: 0mm;
         }
         table {
            page-break-after: always;
            border-spacing:0mm;
         }
         tr {
            vertical-align: bottom;
            height:284mm;
         }
      </style>
   </head>
   <body>
      <table>
         <tr>
            <td>Page 1</td>
         </tr>
      </table>
      <table>
         <tr>
            <td>Page 2</td>
         </tr>
     </table>
   </body>
</html>

css出问题了吗?Chrome是否不知道1毫米的大小?

Is there something wrong with my css or does Chrome not know the size of 1 mm?

推荐答案

我刚刚才知道.设置高度是不够的,我还需要设置宽度.(我仍然需要将高度设置为284而不是285,但这是可以的(可能是舍入误差))

I figured it out just now. It is not enough to set height, I need to set width as well. (I still need to set height to 284 instead of 285, but that is ok (probably a rounding error))

tr {
    vertical-align: bottom;
    height:284mm;
    width:198mm;
}

这篇关于Chrome似乎错误地计算了打印时以毫米为单位的css大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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