简体   繁体   English

在容器div中放置固定大小的div

[英]Positioning fixed sized divs inside container div

So I have a fixed size container div, and fixed sized divs to go inside that container, but what I'm looking for is a way to align the children divs in a certain way like this: 因此,我有一个固定大小的容器div,并且要在该容器中放入固定大小的div,但是我正在寻找的是一种以某种特定方式对齐子div的方法:

我希望div排序

Using the default display:block on the children divs causes them to continue running down the page, ignoring the boundaries of the container div, whilst using display:inline-block causes them to display like this: 在子级div上使用默认的display:block会使它们继续向下运行页面,而忽略容器div的边界,而在使用display:inline-block时,它们将显示为:

div如何与display:inline-block一起显示

Is there something i'm missing from the container div to stop the children overflowing, or is it something i'd need to add to the children? 容器div中是否缺少我要阻止孩子溢出的东西,还是需要添加到孩子中的东西?

Thanks, 谢谢,

Note: The images show just 8 boxes, I plan to use more. 注意:图像仅显示8个框,我打算使用更多框。

CSS3 columns are what you're looking for. 您正在寻找CSS3列。 Here's a sample, HTML: 这是一个示例HTML:

<div class = "container">
    <div class = "entry">Glee is awesome!<br/>1</div>
    <div class = "entry">Glee is awesome!<br/>2</div>
    <div class = "entry">Glee is awesome!<br/>3</div>
    <div class = "entry">Glee is awesome!<br/>4</div>
    <div class = "entry">Glee is awesome!<br/>5</div>
    <div class = "entry">Glee is awesome!<br/>6</div>
    <div class = "entry">Glee is awesome!<br/>7</div>
    <div class = "entry">Glee is awesome!<br/>8</div>
</div>

CSS: CSS:

.container {
    height: 230px; /*2 * 100 + 3 * 10*/
    width: 450px; /*2 * 400 + 5 * 10*/
    -moz-column-count: 4;
    -webkit-column-count: 4;
    column-count: 4; /*4 columns*/
}
.entry {
    height: 100px;
    width: 100px;
    margin: 10px;
    background-color: rgb(0, 162, 232);
    color: white;
    font-family: 'Arial', Helvetica, Sans-Serif;
    text-align: center;
    font-weight: bold;
}

And a little demo: little link . 还有一点演示: 一点链接

I hope that helped! 希望对您有所帮助!

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

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