Search code examples
floating-pointpositioningpixelcss

Validity of CSS positioning by float numbers


I'll make it quick.

Is this considered safe and valid:

box-shadow:         inset 0.5px 0.5px 0.5px 0px #888888;
-moz-box-shadow:    inset 0.5px 0.5px 0.5px 0px #888888;
-webkit-box-shadow: inset 0.5px 0.5px 0.5px 0px #888888;

?

Or is using integers mandatory?


Solution

  • Interestingly enough it can sometimes make sense to have half pixels. From the CSS3 Values and Units docs:

    Normally, the pixel unit refers to physical pixels of the viewing device. However, if the pixel density of the output device is very different from that of a typical computer display, the user agent should rescale pixel values.

    It looks like in certain cases the browser will be required to scale pixels which will most likely result in non-integer values.

    Having said that, I'm not entirely sure how much effect setting it in your own CSS will have.