'property: 0' or 'property: 0px' in CSS?

后端 未结 9 1687
无人及你
无人及你 2020-11-28 10:38

I\'ve seen this notation used a lot, and I was wondering, is there is any notable difference between these two notations?

element#id
{
  property: 0;
}


        
相关标签:
9条回答
  • 2020-11-28 10:55

    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.

    0 讨论(0)
  • 2020-11-28 11:01

    Unit identifiers are optional, but there is no noted performance increase (although you are saving two characters).

    CSS2 - From W3C CSS 2.1 Specification for Syntax and basic data types:

    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.

    (Emphasis mine)

    CSS3 - From W3C CSS Values and Units Module Level 3 (Currently in Candidate Recommendation at the time of this writing)

    For zero lengths the unit identifier is optional (i.e. can be syntactically represented as the 0).

    0 讨论(0)
  • 2020-11-28 11:05

    Zero pixels is equal to zero inches and zero meters and so forth. 0 is all you need.

    0 讨论(0)
提交回复
热议问题