简体   繁体   中英

float div 100% height of container, all dynamic

I've been looking around and I can not find anything that solve this problem.

I have a container div, inside this one, I have few floated div, their content is generated dynamically and can vary from few words to almost a page. this basically create a line of a table (I do not want to use table layout for some reasons).

I successfully made the container expand to the bigger of the content using overflow:hidden;

Now I would like all my divs to adapt to the container height.

you can set a class to all the div's inside the container ... let's say class="contained"

then you can add a js function to run when the document is generated that finds the max-height of all the contained div's and sets the same height to all the others.

  $(function() {
      var maxheight=0;
      $(".contained").each( function ()  {
          if (maxheight<$(this).height()
          maxheight=$(this).height();
      });
      $(".contained").each( function ()  {
      $(this).height(maxheight);
      }); 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM