Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS inch/mm measurements not accurate

I am currently developing a tool for printing labels from the browser. I am running in to an interesting issue where I have labels that are 2.25" x 1.25". As such I have set my print CSS for a div to width: 2.25in; height: 2.25in;

In the chrome inspector, the dimensions appear properly as 2.25in; by 1.25in. Also, my printer is configured correctly as the same coordinates exactly.

When the time comes to print I am actually getting a preview that does not fill the entire 2.25x1.25 print preview.

http://imgur.com/K3BFSgg,CvToRSK,41fqK9D,vIL9lca

The dotted border is the border of the 2.25x1.25 inch div. Completely inaccurate measurement.

Any advice or tips on what could be going wrong? Thank you :)

like image 544
Andrew Hartwig Avatar asked Jun 13 '16 13:06

Andrew Hartwig


People also ask

What are the units of measurement in CSS?

The so-called absolute units (cm, mm, in, pt and pc) mean the same in CSS as everywhere else, but only if your output device has a high enough resolution. On a laser printer, 1cm should be exactly 1 centimeter. But on low-resolution devices, such as computer screens, CSS doesn't require that.

How big is 1cm in CSS?

On a laser printer, 1cm should be exactly 1 centimeter. But on low-resolution devices, such as computer screens, CSS doesn't require that. And indeed, the result tends to be different from one device to another and from one CSS implementation to another.

How do you measure font size in CSS?

Use em or px for font sizes. CSS inherited the units pt (point) and pc (pica) from typography. Printers have traditionally used those and similar units in preference to cm or in.

What is the difference between CM and PT in CSS?

CSS inherited the units pt (point) and pc (pica) from typography. Printers have traditionally used those and similar units in preference to cm or in. In CSS there is no reason to use pt, use whichever unit you prefer.


1 Answers

One inch in CSS (1 in) is defined as 96 pixels (source).
This works on low-density devices where 1 physical pixel = 1 screen pixel.

On high-dpi (dots per inch) devices like printers, it doesn't really work, though.


Seing as you want it to fill the whole viewport, maybe you should take a look at the vh and vw units.
They're described here.

vh stands for viewport-height and vw (you guessed it) stands for viewport-width.

Long story short, 1 vh = 1% of screen height, same for vw (except it's the width).

like image 177
Lukas Gjetting Avatar answered Sep 30 '22 13:09

Lukas Gjetting