Reputation: 7805
I have a difference of 1px
between FF and Chrome in element.offsetWidth
.
I have been reading trying to understand the problem. Tried to reset the CSS, tried to move the element away from near the screen borders (I remember old IE was inacurrate if 10px near the screen broder). Found this answer about FF needing a setTimeout, but no answer about why...
Still no solution. I'm looking to understand/fix it with vanilla JS or CSS.
Question:
Why is this and what can I do in my CSS to get the values consistent?
jsFiddle: http://jsfiddle.net/f35j2/show/
html
<div id="wrapper" style="width: 203px; height: 203px;">
<div id="inner" style="width: 50%; height: 50%; margin: auto; display: block;"></div>
</div>
Upvotes: 2
Views: 2568
Reputation: 96
When I opened your jsfiddle link in chrome and firefox and analysed the values what I got is:
Refer the snapshot below
.
You can exercise the same with boundary values (e.g. 101.4999, 101.9999) to get more idea of this.
Upvotes: 1
Reputation: 167
The width of the inner element is a non integer. FF and Chrome are rounding the number differently. You can get the exact width by using inner.getBoundingClientRect().width (which is 101.5)
This is because the parent element is 203px. Not 202 or 204.
Upvotes: 4