0

所以我有这个代码:

var navWidth = jQuery("ul#navi"), 
    phoneWidth = jQuery("div#phone-number"), 
    diff = navWidth.outerWidth() + phoneWidth.outerWidth();

console.log(navWidth.outerWidth());
console.log(phoneWidth.outerWidth());
console.log(diff);

它显示在控制台中

650 150 850

谁能告诉我为什么它显示 850 为 650 + 150 ?

4

1 回答 1

3

如果您有填充或/和边距,这可以改变您的宽度。

函数 .outherWidth() 返回 div 的宽度,包括内边距、边框和不包括边距。

函数 .innerWidth() 返回 div 的宽度,包括 padding,不包括边框和边距。

函数 .outherWidth(true) 返回 div 的宽度,包括 padding 和 margin。

函数 .width() 返回 div 的宽度,不包括 padding 和 margin。

看看这个链接。

我希望它能解决你的问题。

于 2012-07-05T17:24:30.813 回答