Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting absolute width of margins (issue with margin: auto;)

I'm trying to determine the used value of the margins of an element. My understanding is that this should be returned via .getComputedStyle(). However, it seems that FireFox and Opera don't return the correct values when margin: auto; is used. Firefox returns '0px', and Opera returns '0px' or, occasionally, 'auto':

http://jsfiddle.net/8FXbZ/

I know I could calculate the content width of the parent, and the total width of the child, and use those to calculate the margins, BUT I'm primarily looking at the case when the parent is a flexbox:

http://jsfiddle.net/8FXbZ/1/

Again, the values could possibly be 'reverse-engineered' but that would get relatively complicated (especially if the flexbox has wrapping allowed), so I was wondering if anyone had any other thoughts?

like image 657
Ben Jackson Avatar asked Oct 20 '22 17:10

Ben Jackson


1 Answers

There is a bug in Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=381328 that returns the wrong value.

like image 185
Don Rhummy Avatar answered Oct 23 '22 11:10

Don Rhummy