jquery - Firefox computed margin auto returns 0 -
jquery - Firefox computed margin auto returns 0 -
i have div centred horizontally css :
.bar { height: 38px; width: 970px; margin-left: auto; margin-right: auto; }
i need have element have same margin right .bar, i'm using jquery sizes :
<div class="spec">i need aligned same.</div>
js:
$(".spec").css('margin-right', $('.bar').margin().right + 'px');
this works, not in firefox 30.0, returns 0 computed margin-right of .bar. suggestions ? http://jsbin.com/difobu/1/edit.
$('.bar').css('margin-right') homecoming 0px in ff 30.0 well. if donwnvote please provide explanation.
unfortunately, comes downwards browser differences. quote an reply similar problem:
as why chrome , ie homecoming different values: .css()
provides unified gateway browsers' computed style functions, doesn't unify way browsers compute style. it's not uncommon browsers decide such border cases differently.
so you're kinda screwed. have few options create consistent.
you can reliably homecoming auto
hiding element before compute style. might work:
var $bar = $('.bar'); $bar.hide(); var barmarginright = $('.bar').margin().right; // "auto" // whatever need value $bar.show();
you can utilize jquery's $('.bar').offset()
, returns properties might able use.
// might not want, but... $('.spec').css('margin-left', $('.bar').offset().left + 'px');
you can seek prepare problem css, though we'd need see whole page decide that.
jquery css firefox margin
Comments
Post a Comment