property: 0' or 'property: 0px' in CSS?
While the unit is optional when the value is 0
, I tend to leave it in, as I can then tweak the values with Chrome's Developer Tools by clicking on the value and pressing the up/down arrow keys. Without a unit, that isn't really possible.
Also, CSS minifiers strip the units off of 0
values anyways, so it won't really matter in the end.
Size of zero pixels in CSS with or without 'px' suffix?
They are identical.
Use width: 0
, because it is shorter and more readable.
Especially when you have, for example:
padding: 0px 0px 9px 8px
vs
padding: 0 0 9px 8px
See the specs:
The format of a length value (denoted
by <length> in this specification) is
a <number> (with or without a decimal
point) immediately followed by a unit
identifier (e.g., px, em, etc.).
After a zero length, the unit identifier is optional.
The minor problem with '0' is that if
you change it to some non-zero value,
you might forget to add the 'px'. And
when making a value '0', you may
forget to remove the 'px'
This does not happen once you get into the habit of writing 0
without the unit identifier.
CSS: left:0 or left:0px
For CSS, whatever the unit 0 is always 0. There is no reason to add this unit.
The spec makes it clear :
After a zero length, the unit identifier is optional.
property: 0.5px' or 'property: .5px' in CSS?
Both are correct. This is stated in section 4.3.1. Specifically:
A <number> can either be an <integer>, or it can be zero or more digits followed by a dot (.) followed by one or more digits.
The only difference between them is a 0
character; whether you choose to include the leading 0
is entirely up to individual preference.
Using 0px instead of 0 in the following context
They both work, so it's pretty much personal preference.
0 is special in that it means 0 of any unit presented but I usually declare the unit of measurement for ease of reading.
http://jsfiddle.net/Kyle_Sevenoaks/UFgpt/
Related Topics
What Are the Default Top, Left, Botton or Right Values When Position:Absolute Is Used
How to Use Font Awesome from Webjars.Org With Jsf
Set Flexbox Children to Have Different Heights to Use Up Available Space
Specify an Svg as a Background Image and Also Style the Svg in Css
Outlining and Partially Filling an Svg Shape
Why Does CSS Float Not Change the Width of the Following Div
How to Cancel Opacity for a Child Element
How Does the CSS Specificity Work
CSS Div Stretch 100% Page Height
Div's VS. Tables or CSS VS. Being Stupid
Absolute VS Relative Position Width & Height
Float:Right Reverses Order of Spans
Double Border with Different Color
How to Style the Resize Grabber of Textarea
Changing Font Colour in Textboxes in Ie Which Are Disabled