将可见节点的样式宽度 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 |