只是一个简短的问题,以澄清我对 CSS perspective
上的单位的一些困惑。
在 CSS Transforms 规范中,它用 px
引用它,例如perspective: 1000px;
但我已经使用过并且在许多其他地方其他人在没有 px
的情况下使用过它,例如perspective: 1000;
例如 W3Schools。
哪种方式更受欢迎?重要吗?
只是想解决这个问题,谢谢。
最佳答案
仅仅因为它被(某些)浏览器接受并不意味着它是正确的。 指定测量单位是 required by the CSS spec ,除非值为零。
规范说:
Lengths refer to distance measurements and are denoted by <length> in the property definitions. A length is a dimension. A zero length may be represented instead as the <number> ‘0’. (In other words, for zero lengths the unit identifier is optional.)
A dimension is a number immediately followed by a unit identifier.
(强调我的)
参见 Distance Units和 Other Units例如。
另请参阅 length 的 MDN 讨论
关于css - 在 CSS 透视图上使用单位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11997177/