【问题标题】:jQuery outerHeight doesn't work properly?jQuery outerHeight 不能正常工作?
【发布时间】:2011-04-16 11:41:01
【问题描述】:

链接的风格:

#carousel ul li {
    display: inline-block;
    border: solid 1px red;
    margin: 50px 25px 50px 25px;
    width: 350px;
    height: 300px;
}

jQuery的代码:

var height = $("#carousel ul li").outerHeight(); 

document.write(height);

它说元素的高度是 302px !为什么?可能是带边框的 302,但 outerHeight 不应显示 300 + 2 + 100(上下边距均为 50 像素)。

我很困惑。

谢谢。

【问题讨论】:

    标签: jquery height


    【解决方案1】:

    不。保证金不计算在内。高度、边框和内边距是。

    如果你的 li 包含的块元素的边距被计算在内。

    【讨论】:

      【解决方案2】:

      试试:

      var height = $("#carousel ul li").height(); 
      

      或者:

      var height = $("#carousel ul li").css('height'); 
      

      【讨论】:

        【解决方案3】:

        默认情况下,outerHeight() 不包括边距。传递 true 以在计算中包含边距,如下所示:

        var height = $("#carousel ul li").outerHeight(true);
        

        【讨论】:

        • 很好的答案!真的救了我的命!
        猜你喜欢
        • 1970-01-01
        • 2016-07-01
        • 2011-12-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-16
        相关资源
        最近更新 更多