Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Default Units

Tags:

css

Can I change the default unit from pixel to mm? For example I want when move an element left and top to be in mm not in pixel?

like image 695
Ilian Avatar asked Feb 16 '10 10:02

Ilian


People also ask

What are the 3 measurements used in CSS?

CSS supports a number of measurements including absolute units such as inches, centimeters, points, and so on, as well as relative measures such as percentages and em units. You need these values while specifying various measurements in your Style rules e.g. border = "1px solid red".

How many pixels is 1vh?

Ex: The value of “1vh” will be 10 pixels (px), and the value of “10vh” will be 100px if the viewport is 1200px wide and 1000px high.

What is the unit for height in CSS?

Pixels are the most commonly used and accepted unit. And it's considered the base of measurement for many other units. It provides the most consistent result among various devices. The box element in the following example has a height of 150px and width of 150px, and it will remain the same on all screen sizes.


2 Answers

Specifying CSS units is a requirement for non-zero values. Browsers may try to guess what you meant, but it would still be a broken stylesheet according to the standard.

I.e. there is no "default unit" in CSS2, it's just that the browser may try to help you out, although it may as well just ignore your statement that doesn't specify units as an invalid one.

like image 197
dpq Avatar answered Oct 17 '22 04:10

dpq


There is no 'default unit'. The CSS spec requires that a length (other than zero) that is missing a unit be treated as an error (and thus ignored).

In quirks mode (and you should almost never be using quirks mode, it makes life more difficult), most browsers will perform error recovery and assume you meant pixels (despite the spec forbidding this).

From the standard:

A <quirky-length> is syntactically identical to a <number-token>, and is interpreted as a 'px' length with the same value.

(In other words, Quirks Mode allows all 'px' lengths in the affected properties to be written without a unit, similar to unitless zero lengths.)

If you are working with screen media — avoid physical units. Most systems are not calibrated to calculate the DPI correctly (so when converting from physical units into something a monitor understands (pixels) they get it wrong).

like image 25
Quentin Avatar answered Oct 17 '22 05:10

Quentin