简体   繁体   English

浮动 div 100% 容器高度,全动态

[英]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.我有一个容器 div,在这个里面,我有几个浮动的 div,它们的内容是动态生成的,可以从几个单词到几乎一个页面变化。 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;我使用overflow:hidden;成功地使容器扩展到更大的内容overflow:hidden;

Now I would like all my divs to adapt to the container height.现在我想让我所有的 div 适应容器的高度。

you can set a class to all the div's inside the container ... let's say class="contained"您可以为容器内的所有 div 设置一个类...假设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.然后你可以添加一个 js 函数来在生成文档时运行,该函数找到所有包含的 div 的最大高度,并为所有其他人设置相同的高度。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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