Scale 'mm' to 'pixels' in CSS [dup

2019-09-22 02:16发布

问题:

This question already has an answer here:

  • Detecting the system DPI/PPI from JS/CSS? 12 answers

I have a container with every measurement defined in 'mm' for printing purposes. However, I want to show its preview inside a 600px wide block with perfect fit. What would be the best way to scale it down?

回答1:

The millimiter to pixels and vice-versa formula takes the DPI of the screen into consideration.

DPI meaning dots-per-inch.

There's no truth in mm to pixels unless you have a stable DPI value you can use.

Anyway, this is the formula:

mm = (pixels * 25.4) / dpi

The most-usual seen DPI values seen are 72 and 96 if I'm not mistaken, but since this is for print it will most likely depend on the printer settings



回答2:

I found this website that converts pixels to mm or vice versa: http://www.unitconversion.org/typography/millimeters-to-pixels-y-conversion.html

According to it, 600px is approximately 159mm.

However there is a problem. Pixel size depends on the resolution of the screen so I'm not really sure how that website came up with its conversion.



回答3:

1 millimeter = 3.779527559055 pixel

therefore: 600px/3.7xxxx = 158.75