[英]“Float up left”? Make divs start at the top of container and grow down
I have a larger div with smaller divs in it. 我有一个较大的div,其中有较小的div。 This is how it currently look:
当前是这样的:
However, I want it to look like this: 但是,我希望它看起来像这样:
Basically, I want all the divs inside the "div-container" to float up and left as opposed to left and down.
基本上,我希望“ div容器”内的所有div上下浮动,而不是左右浮动。 Perhaps float is not the thing I am looking for.
也许浮动不是我想要的东西。 How should I go about this issue?
我应该如何处理这个问题?
Here you can see for yourself: https://jsfiddle.net/sebastian3495/ea6L08bu/9/ 在这里您可以自己看到: https : //jsfiddle.net/sebastian3495/ea6L08bu/9/
html HTML
<div class="container">
<div class="box" style="background: yellow;"></div>
<div class="box" style="height: 200px;background: brown;"></div>
<div class="box" style="background: green;"></div>
<div class="box" style="background: purple;"></div>
</div>
css CSS
.container {
background: red;
width: 500px;
height: 500px;
border: 2px solid black;
overflow: hidden;
}
.box {
display: inline-block;
height: 100px;
width: 100px;
}
If you are using inline-block
then you just need to use vertical-align:top
如果您使用
inline-block
,则只需要使用vertical-align:top
.container { background: red; width: 500px; height: 500px; border: 2px solid black; overflow: hidden; } .box { display: inline-block; height: 100px; width: 100px; vertical-align: top; }
<div class="container"> <div class="box" style="background: yellow;"></div> <div class="box" style="height: 200px;background: brown;"></div> <div class="box" style="background: green;"></div> <div class="box" style="background: purple;"></div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.