css - 如何根据父div中子div的数量设置div的高度

标签 css html height

在此页面 bonusnavigator.ru

我有一个 div:.toppanel .topcasino .inner

它现在显示 11 个分割 - .toppanel .topcasino .inner .row -(交易)。当我尝试减少交易数量时,我得到了这个:

http://screencast.com/t/eajlX3xNTm2

我如何设置 css 以便子 div 像这样填充释放的空间:

http://screencast.com/t/vKlPct3Avb4V

提前谢谢大家。

更新:感谢前两个建议,但它们处理的是“发布结果”。我想问的是如何设置子 div(交易)以根据父 div 中的交易数量动态更改高度以填充可用空间。

最佳答案

我没有玩过你的 CSS,但你在使用 jquery 吗?如果是这样,您可以使用 height() 函数根据交易数量设置高度。

您可以使用 $(".inner").height(); 获取容器 div 的高度;

然后将高度除以其中的 DIV 数,并将所有子 Div 的高度设置为该值。像这样(语法可能不正确,因为我只是在这里输入代码):

var containerHeight = $(".inner").height();
var divCount = $(".inner > div").length; /* returns the number of DIVs which are direct children of the parent */
var divHeight = Math.Round(containerHeight/divCount); /* number being the count of your divs */
$(".inner > div").height(divHeight);

关于css - 如何根据父div中子div的数量设置div的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20787427/

相关文章:

ios - Collection View 单元格大小取决于 UITextView

html - div css高度调整

jQuery Tabs 高度溢出我的其他 div

html - 根据返回的数据库值选中/取消选中复选框

jquery - 当宽度不够时,使 Bootstrap 导航栏中的可扩展搜索表单出现在其他所有内容之上

html - css二级下拉菜单

html - 图库插件位置在调整大小时移动

html - 如何使 flex-wrap 平衡其包裹的元素?

javascript - 如何让 Google map 搜索栏位于半透明全宽 div 中

javascript - HTML 5 Canvas : detect long click