使用jQuery在firefox中获取自动计算的边距

使用jQuery在firefox中获取自动计算的边距,jquery,firefox,cross-browser,Jquery,Firefox,Cross Browser,使用下面的标记和css,我试图获得shell的计算左边距 <section class="page-title"> <div class="shell"> <h5 class="title">Welcome!</h5> </div> </section> .shell { zoom: 1; max-width: 1000px; margin-left: auto

使用下面的标记和css,我试图获得shell的计算左边距

 <section class="page-title">
      <div class="shell">
        <h5 class="title">Welcome!</h5>
      </div>
    </section>

.shell {
  zoom: 1;
  max-width: 1000px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 16px;
  padding-right: 16px;
}
它可以在Chrome、Safari、IE9中使用,但令人惊讶的是,它不能在Firefox中使用。尝试了另一种方法:

($('.shell').outerWidth(true) - $('.shell').outerWidth()) / 2
除了Firefox,它也可以很好地工作。所以我猜firefox不支持通过jQuery获得未定义的css?解决这一问题的直接方法是:

($('.page-title').width() - $('.shell').outerWidth()) / 2 

但我想知道是否有更好的办法

当您说它不工作时,您是(在控制台中)收到错误还是返回0?返回0作为自动设置显然是不同浏览器的问题


您可以使用轻量级库,它以像素为单位返回所有度量。这将使您不必再费劲地处理外径等问题。

我与Firefox v21I有完全相同的问题。我与Firefox v37.0.1有相同的问题。此库在
margin:auto
时返回0。在这种情况下,有没有办法获得利润?jQuery(可能还有vanilla JS)也会为“auto”返回0px。我认为您无法可靠且一致地跨浏览器获取值
auto
。“自动”的意思是“由浏览器决定”,您正在读取的正是基于浏览器的值。(剩余边距等返回什么?)
($('.page-title').width() - $('.shell').outerWidth()) / 2