css - '属性 : 0' or ' property: 0px' in CSS?

标签 css properties zero

我看到这种表示法被大量使用,我想知道这两种表示法之间有什么显着的区别吗?

element#id
{
  property: 0;
}

element#id
{
  property: 0px;
}

我一直使用 property: 0px;,因为我觉得它看起来更干净,但我不确定浏览器对 0px 的解释是否与 不同>0

有谁知道哪个更好或更正确?

最佳答案

单位标识符是可选的,但没有显着的性能提升(尽管您节省了两个字符)。

CSS2 - 来自 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.

(强调我的)

CSS3 - 来自 W3C CSS Values and Units Module Level 3 (目前在 Candidate Recommendation 在撰写本文时)

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

关于css - '属性 : 0' or ' property: 0px' in CSS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4318471/

相关文章:

html - 粘性元素不适用于 Iphone CSS HTML

c# - 属性 : Internal get, 保护集

c# - 通过多个类传播属性更改

ios - 私有(private)变量是否需要声明属性?

php - zerofill一个整数php

matlab - 查找 0's separating islands of 1' 的长度并分配它们

jquery - 将绝对位置元素右对齐并保持响应

css - 为什么 404 页面包含内联 CSS

html - 在 div 列内垂直居中对齐

c++ - 区分零和负零