CSS 像素可以是一个分数吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9080633/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can a CSS pixel be a fraction?
提问by Kees C. Bakker
Can a CSS px
be a fraction? Is it allowed by the standards? And if so, do the major browsers support it?
CSSpx
可以是一个分数吗?标准允许吗?如果是这样,主要浏览器是否支持它?
Let's back the answers up with documentation, folks.
伙计们,让我们用文档来支持答案。
采纳答案by Guffa
Yes, you can specify fractional pixels. As this has been part of CSS since the very first version, it should be well supported by any browser that supports CSS at all.
是的,您可以指定小数像素。由于这从第一个版本开始就成为 CSS 的一部分,因此任何支持 CSS 的浏览器都应该很好地支持它。
Reference: CSS 2.1: 4.3.2 Lengths
"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.)."
“长度值的格式(在本规范中由 <length> 表示)是一个 <number>(带或不带小数点)后紧跟一个单位标识符(例如,px、em 等)。”
When the elements are displayed on the screen, most browsers will naturally round the position to the nearest pixel when using 100% zoom level. On higher zoom levels you will notice that fractional pixel values are recognized.
当元素显示在屏幕上时,大多数浏览器在使用 100% 缩放级别时会自然地将位置四舍五入到最近的像素。在更高的缩放级别上,您会注意到可以识别小数像素值。