CSS宽度中的小数位是否受到尊重? [英] Are the decimal places in a CSS width respected?

查看:122
本文介绍了CSS宽度中的小数位是否受到尊重?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在做CSS设计时,我一直在想一会儿。

Something I've been wondering for a while whilst doing CSS design.

css宽度中的小数位是否受到尊重?

Are decimal places in css widths respected? Or are they rounded?

.percentage
{
    width: 49.5%;
}

.pixel
{
    width: 122.5px;
}


推荐答案

然后是的,它受到尊重。正如Martin指出的,当你得到分数像素时,事情会崩溃,但是如果你的百分比值产生整数像素值(例如,在示例中为200px的50.5%),你会得到明智的预期行为。

If it's a percentage width, then yes, it is respected. As Martin pointed out, things break down when you get to fractional pixels, but if your percentage values yield integer pixel value (e.g. 50.5% of 200px in the example) you'll get sensible, expected behaviour.

修改:我更新了示例,以显示小数像素的变化(在Chrome中,值会被截断,因此50,50.5和50.6都显示相同的宽度)。

I've updated the example to show what happens to fractional pixels (in Chrome the values are truncated, so 50, 50.5 and 50.6 all show the same width).

这篇关于CSS宽度中的小数位是否受到尊重?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆