我看到这种表示法被大量使用,我想知道这两种表示法之间有什么显着的区别吗?
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/