简体   繁体   English

当div向下移动时,调整其余部分的大小以占用剩余空间

[英]When a div moves down, resize the rest to take up the remaining space

I have three (but the problem is applicable to any amount) divs that have a percentage width and scale with the size of their container but have a minimum width where they will move down in the container. 我有3个div(但该问题适用于任何数量),它们的宽度和百分比随容器的大小而定,但具有最小的宽度,它们将在容器中向下移动。 Here is an example of the current scenari: 这是当前场景的一个示例:

div {
  float: left;
  width: 33%;
  min-width: 300px;
  height: 300px;
  margin-right: 2px;
}

<div style="background: red"></div>
<div style="background: green"></div>
<div style="background: blue"></div>

http://jsfiddle.net/ULLBr/ http://jsfiddle.net/ULLBr/

I was wondering if it was possible for the remaining elements to scale then to take up the remaining whitespace on the 'row'? 我想知道剩余元素是否有可能扩展,然后占据“行”上的剩余空白?

I know this could be achieved in javascript but a pure CSS solution would be much appreciated, however if that is not possible what would be the best way to approach it in javascript? 我知道这可以用javascript实现,但是纯CSS解决方案将不胜感激,但是如果不可能的话,用javascript处理它的最佳方法是什么?

Ideally either solution should be able to handle n divs. 理想情况下,任何一种解决方案都应该能够处理n个div。

Thank you. 谢谢。

I would suggest you take a look at flex box. 我建议您看一下flex box。

I have created a jsfiddle here which I think is what you are trying to achieve. 我在这里创建了一个jsfiddle ,我认为这是您想要实现的目标。 Also worth looking at and where I adapted it from is css tricks great site. 另外值得一看的地方以及我从中改编的地方是CSS技巧很棒的网站。

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

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