【发布时间】:2015-04-08 07:01:00
【问题描述】:
我有很多带有文本的 div,我希望它们能够很好地彼此相邻并在彼此下方对齐。
(我读过一些人说我应该为这些创建一个父 div,并给父级一个相对位置,给子级一个绝对位置,但这对我不起作用)
但它不会起作用。
I found this lay-out with shows exactly what I want mine to do
HTML
<div class="block">
<!--<div class="blockboxgrid">-->
<div class="blockbox">
<h2>Title</h2>
<p>
Text
</p>
</div>
<!--</div>-->
</div>
CSS
/*.blockboxgrid{
position:relative; <<< I saw this example while googling, to make the area where the box is in relative, and the box itself absolute. But this didn't work for me either.
}*/
.blockbox {
/*position:absolute;*/
background-color:#fff;
border-radius: 4px;
border:8px solid #ff6b6b;
display: block;
float: left;
margin: 10px;
width: 330px;
color:#000;
transition: all 0.5s ease;
}
【问题讨论】:
-
你可以更好地使用
- 和
- 标签并将所有 div 作为子元素放在每个
- 标签内。
-
@frebinfrancis 是的,这会起作用 - 这里的方法相同:stackoverflow.com/a/8896548/1163786 - 这是 isotope.metafizzy.co 或 masonry.desandro.com 的布局工作。仅靠 CSS 无法真正解决,需要重新计算网格。
标签: html css alignment css-float positioning