When specifying a 0 value in CSS, should I explicitly mark the units or omit?

后端 未结 8 1192
旧巷少年郎
旧巷少年郎 2020-12-16 09:13

This is more of a \'philosophy\' argument, but I\'d like to know what the recommended practice here. I\'m not setting it up as a Wiki yet in case there is an \'official\' an

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-16 09:38

    I'm gradually starting to believe in zeros with units.

    I follow a style guide that says to use unitless zeros. I also think they look better. I agree with all the pro-unitless arguments on here. But twice in my career a bug has been caused by unitless zeros. (one having to do with calc and one having to do with a transition from 0 to something - but I can't remember the details.)

    With "causes bugs" on one side of the equation can any pro-unitless argument compete no matter how aesthetically pleasing or logical?


    BTW, I originally attributed the unitless zero style to Airbnb's guide, but after rereading it, it doesn't actually say that explicity, but comes close: https://stackoverflow.com/a/55391061/2836695

提交回复
热议问题