offsetHeight and offsetWidth inconsistent on children of flexbox with justfy-content other than flex-start
Reported by
justin.m...@hotmail.com,
Mar 31 2016
|
|||
Issue descriptionUserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2695.1 Safari/537.36 Steps to reproduce the problem: 1. Create a div with display: flex and justify-content set to anything other than flex-start 2. Place some divs inside it all with same percent width (if flex-flow:row) or percent height (if column) without overflowing 3. Compare the offsetWidth (if rows) or offsetHeight (if columns) of the children elements What is the expected behavior? The offsetWidth (if rows) or offsetHeight (if columns) for all of the children elements should be the same due to them having the same percentage. Getting the width or height using getComputedStyle works this way. What went wrong? The offsetWidth or offsetHeight values are often not the same despite the equal percent width/height values. They do sometimes match under seemingly-random circumstances (see comments). Did this work before? N/A Chrome version: 51.0.2695.1 Channel: canary OS Version: 10.0 Flash Version: Shockwave Flash 21.0 r0 Example/testing for height: http://codepen.io/justinm53/full/grxQNE/ - Only under some combinations of parent height and justify-content value do the heights in this example match. - Only seems to happen with justify-content being changed from flex-start (default).
,
Mar 31 2016
Can you clarify what values you see? I see values that are similar except for rounding. Is that the issue you see too? If yes: Due to the way we pixel-snap this is probably expected.
,
Mar 31 2016
cbiesinger is correct -- the offsetHeight value attempts to give you the on-screen representation, which with a box with a height of 49.9px will vary between 50 and 49. If you want the sub-pixel height, use getBoundingClientRect(). That returns your expected value for all boxes.
,
Mar 31 2016
Alright, I understand now, apologies for the misunderstanding. I arrived at this issue because jQuery's $(el).height() uses offsetHeight, and I figured their common height function would be the "exact" height as oppose to the on-screen height. I'm not going to bother considering that an issue on their part, though. Thanks for the quick responses, though. I'll definitely keep this little detail in mind in the future.
,
Mar 31 2016
No problem! Thanks for taking the time to file an easy-to-follow issue :) |
|||
►
Sign in to add a comment |
|||
Comment 1 by justin.m...@hotmail.com
, Mar 31 2016