JQuery .height() 没有按预期工作

标签 jquery html css

我正在制作一个日历网站。在这里,我有一个日历 div,其中加载了日历,包裹在一个内容 div 中。 在此页眉和页脚位置固定。日历在蓝色部分加载。

enter image description here

HTML

<div class ="content">
   <div id="calendar"></div>
</div>

CSS

.content{
   background: #fcfcfc;
   height: 100%;
   margin: -70px 0 -20px;
   padding: 70px 0 20px;
}

#calendar{
   background: #fcfcfc;
   margin: 10px 10px 10px 10px;
   border: 1px solid #888;

}

JS

var calHeight = $(".content").height();

从图像中我认为 calHeight 应该给出大约 390,但它在 chrome 中给出 594,在 firefox 中给出 565。

我应该怎么做才能使 calHeight 显示的大小?

最佳答案

尝试使用 jQuery.outerHeight()。

http://api.jquery.com/outerHeight/

它返回包含 Margin 和 Padding 的高度。

关于JQuery .height() 没有按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18373841/

相关文章:

jquery - 调整大小时的菜单过渡

jquery - 可排序和可删除 : CSS preventing jquery-ui sortable to drag around the dropped items

jQuery .each() 函数。重置索引?

html - 在 Bootstrap Segmented 输入组右侧添加圆 Angular

html - 如何让固定容器的滚动条出现在固定子容器的前面?

javascript - 有没有更简洁的方式来编写JS来显示和隐藏?

javascript - 屏幕宽度变化时无法使 div 元素居中

javascript - OKZoom 插件不适用于带有 svg 过滤器的图像

css - 标题菜单大小没有响应

javascript - 无法同时为 2 个对象设置动画