【发布时间】:2014-02-05 15:58:09
【问题描述】:
如何将 class="container" 的新高度设置为数据末尾?
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.js"></script>
<style type="text/css">
.container {
background: green;
position: relative;
}
.absolute1 {
position: absolute;
background: red;
float: left;
width: 200px;
height: 200px;
}
.absolute2 {
position: absolute;
background: red;
float: left;
left: 210px;
width: 200px;
height: 150px;
}
</style>
<script type="text/javascript">//<![CDATA[
$(window).load(function(){
$( document ).ready(function() {
$( ".container" ).each(function() {
var newHeight = 0, $this = $( this );
$.each( $this.children(), function() {
newHeight += $( this ).height();
});
$this.height( newHeight );
});
});
});//]]>
</script>
<div class="container">
<div class="absolute1">
Testing absoluteTesting absoluteTesting absoluteTesting absoluteTesting absolute<br />
Even more testing absolven more testing absolven more testing absolven more testing absolven more testing absolute<br />
</div>
<div class="absolute2">
Testing absoluteTesting absoluteTesting absoluteTesting absoluteTesting absolute<br />
Even more testing absolven more testing absolven more testing absolven more testing absolven more testing absolute<br />
</div>
</div>
------------------footer text------------------
【问题讨论】:
-
“数据结束”是什么意思?
-
旁注:你不需要
$(window).load()AND$(document).ready()
标签: javascript jquery css height