Jquery not compatible with box-sizing?
Jquery not compatible with box-sizing?
目前我想做的就是使用
获取div的高度$(header).height()
页眉是div元素。
当前在我的css中,我有以下内容:
*, *:before, *:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
这意味着所有的填充、边框等都不会影响元素的总大小。而且看起来效果还不错。但是当我用$(element).Height()
创建一个方程并且对象有填充或边框时,即使box-sizing
被设置为border-box
,它也会将这些额外的大小添加到div的尺寸中。
示例:http://jsfiddle.net/CeuBQ/
嗯,似乎我在写问题的时候就发现了问题所在。
显然,div实际上并没有使用box-sizing:
保持它的尺寸,但是边界或填充从它们中减去。我必须说一件有趣的事,我从来没有想过。
但是,要获得元素的实际高度,您需要使用jQuery的outerHeight函数,该函数包含padding - border等。
( $(headerPad).outerHeight() );
http://jsfiddle.net/CeuBQ/2/
变化
$(header).height()
$(header).innerHeight()
jquery .innerHeight();
将排除填充和边框,只计算宽度;
相关文章:
- Fighting with FRP
- issue with FB.Event.subscribe
- 在localhost Dev Box上测试JSONP请求的最佳方式
- geolocation-marker.js conflict with markerclusterer.js
- Angular 2.0 with JavaScript or TypeScript?
- 为什么不推荐使用“with”?是否有更好或其他方法可以“下降”到对象的命名空间
- WebComponentsJS with IE10
- 指令的模板必须只有一个根元素:With restrict E&替换true
- 将po-box javascript正则表达式转换为c#regex
- timeago.js with datatable and PHP
- Ajax and Json with Rails
- errors with Javascript try catch
- 谷歌地图API v3:Initial View is Fine,but Gray Box with No Map if
- Dojo Combo Box with error "store.fetch is not a functio
- JQuery# Live Filter conflict with Fancy Box
- jQuery select box with respect to the change event
- Centering content in a flex box with a background using '
- Jquery not compatible with box-sizing?
- 无法确定box-sizing, media queries或javascript
- jQuery superfish在使用box-sizing属性时添加了隐藏在ul标签上的溢出