为什么 CSS 在使用毫米单位时为宽度和边距设置不同的计算样式?

问题描述 投票:0回答:0

将可见节点的样式宽度 or marginLeft 更改为

10px
给出相同的计算样式:10px.

然而,在几个导航器上,它给出了不同的结果

1mm
.

为什么?

我运行了这段代码:

const d = document.body.appendChild(document.createElement('div'));
d.style.marginLeft = d.style.width = '1mm';
const cs = window.getComputedStyle(d);
console.log(cs.width, cs.marginLeft);

它给出了这些结果:

财产 铬 111 火狐 111 webkitgtk 2.40
宽度 3.76562px 3.78333px 3.765625px
左边距 3.77953px 3.77953px 3.779528px
javascript css dom units-of-measurement
© www.soinside.com 2019 - 2024. All rights reserved.