javascript - jQuery container Div height not expanding -


i have used jquery code expand height of divs within container. here jsfiddle link.

however when resizing browser width divs height fixed , text overflows container. can following code changed expand container height , divs within text stays within?


jquery code:

$(window).load(function () { $(window).resize(function () {      $(document).ready(function () {         var heightarray = $(".container>div").map(function () {             return $(this).height();         }).get();         var maxheight = math.max.apply(math, heightarray);         $(".container>div").height(maxheight);         $(".container>div").height(maxheight);     });  }).trigger('resize'); }); 

style:

.container { height: auto; float:left; }  #half { width:48%; margin:0.5%; padding:0.5%; float:left; background-color:#1589ff; } 

html:

<div class="container"> <div id="half">      <h1>about</h1>     <p>lorem ipsum dolor sit amet, consectetur adipiscing elit. aliquam sodales urna non odio egestas tempor. nunc vel vehicula ante. etiam bibendum iaculis libero, eget molestie nisl pharetra in. in semper consequat est, eu porta velit mollis nec. lorem ipsum dolor sit amet, consectetur adipiscing elit. aliquam sodales urna non odio egestas tempor. nunc vel vehicula ante. etiam bibendum iaculis libero, eget molestie nisl pharetra in. in semper consequat est, eu porta velit mollis nec. curabitur posuere enim eget turpis feugiat tempor. etiam ullamcorper lorem dapibus velit suscipit ultrices. proin in est sed erat facilisis pharetra.</div>  <div id="half">      <h1>news</h1>     <p>lorem ipsum dolor sit amet, consectetur adipiscing elit. aliquam sodales urna non odio egestas tempor. nunc vel vehicula ante. etiam bibendum iaculis libero, eget molestie nisl pharetra in. in semper consequat est, eu porta velit mollis nec. lorem ipsum dolor sit amet, consectetur adipiscing elit. aliquam sodales urna non odio egestas tempor. nunc vel vehicula ante. etiam bibendum iaculis libero, eget molestie nisl pharetra in.    </div> </div> 

you setting fixed height when resizing first time have set height auto resize divs know desired size should be. otherwise max height getting fixed height set first time.

function resizedivs() {     var heightarray = $(".container>div").map(function () {         return $(this).height();     }).get();     var maxheight = math.max.apply(math, heightarray);     $(".container>div").height(maxheight);     $(".container>div").height(maxheight); }  $(function () {     resizedivs(); });  $(window).resize(function () {     $(".container>div").css('height', 'auto');     resizedivs(); }); 

jsfiddle

http://jsfiddle.net/xxxne/11/


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -