简体   繁体   English

如何根据底部div调整顶部div的大小

[英]How to resize the top div according to the bottom div

I have a top div with chart and bottom div contains four rows at the end of each row i have close icon on click of that close icon the particular row disappears, so that the remaining rows should go down the top div should occupy the remaining space how to do it in css or javascript.我有一个带有图表的顶部 div,底部 div 在每行的末尾包含四行我点击该关闭图标时有关闭图标,特定行消失,因此剩余的行应该向下移动,顶部 div 应该占据剩余空间如何在 css 或 javascript 中做到这一点。 I am using the concept of ng-repeat from Angular JS so that the rows are getting repeated.我正在使用 Angular JS 中的 ng-repeat 概念,以便重复行。

If the number of rows below may change, I'd suggest using flexboxes.如果下面的行数可能会改变,我建议使用 flexboxes。 On the parent div (which wraps both chart and rows):在父 div(包装图表和行)上:

display: flex;
flex-direction: column;

And on the chart-wrapper:在图表包装器上:

flex: 1 0 0%; 

This will make the chart-wrapper div take all the remaining space of the parent div.这将使图表包装器 div 占据父 div 的所有剩余空间。 If you'd like to support older browser, don't forget vendor prefixes:如果您想支持旧版浏览器,请不要忘记供应商前缀:

display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;

-webkit-flex-direction: column;
-moz-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;

And:和:

-webkit-box-flex: 1 0 0%;
-moz-box-flex:  1 0 0%;
-webkit-flex:  1 0 0%;
-ms-flex:  1  0 0%;

If you haven't already, take some time to read more about flexboxes.如果您还没有,请花一些时间阅读有关 flexbox 的更多信息。 Some people claim that this is the best things that was added to CSS over years, and I have to agree - they solve a lot of layout problems.有些人声称这是多年来添加到 CSS 中的最好的东西,我不得不同意——它们解决了很多布局问题。

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

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