html - 在复制纸张交互的 Web 应用程序的 CSS 上使用 cm/mm 是一个好习惯吗?

标签 html css w3c

我正在构建一个 Web 应用程序,该应用程序可以与文档进行交互以便稍后打印。在某些方面类似于 Google Docs。我正在考虑在我的文档页面的 CSS 上使用 cm/mm,因为它会帮助我生成文档。示例:

// A4 size
.page {
   width: 210mm;
   height: 297mm;
   margin: 2cm 5cm; 
}
<div class="page">
  ...
</div>

采用这种方法的主要问题是什么?

最佳答案

W3C 有一篇关于 CSS units 的精彩文章.特别是:

cm: Not recommended for screen / recommended for print

The so-called absolute units (cm, mm, in, pt and pc) mean the same in CSS as everywhere else. A length expressed in any of these will appear as exactly that size (within the precision of the hardware and software). They are not recommended for use on screen, because screen sizes vary so much. A big screen may be 60cm (24in), a small, portable screen is maybe only 8cm. And you don't look at them from the same distance.

The only place where you could use pt (or cm or in) for setting a font size is in style sheets for print, if you need to be sure the printed font is exactly a certain size. But even there using the default font size is usually better.

关于html - 在复制纸张交互的 Web 应用程序的 CSS 上使用 cm/mm 是一个好习惯吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16297619/

相关文章:

html - 图标字体不再在 WordPress 网站上显示字符

Javascript 动态更改输入类型在 IE8 上不起作用

css - 为什么不用margin-top : auto and margin-bottom:auto work the same as their left and right counterparts?

javascript - 支付请求 API - 支付现金选项

android - 如何在iphone和android手机上运行本地html文件?

javascript - 如何消除 html 中图像加载的延迟?

jquery - 将鼠标悬停在一个元素上以更改另一个元素

html - 对齐标签和自定义复选框

html - (X) 计算机可读格式的 HTML & CSS 定义描述

javascript - 使用 native DOM 的最近祖先匹配选择器?