如何自动在父级内部垂直堆叠div? [英] How do I automatically stack divs vertically inside a parent?
本文介绍了如何自动在父级内部垂直堆叠div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这就是我要完成的工作...
Here's what I am trying to accomplish...
- 父母"的位置是:相对
- "div 1-3"的位置为:绝对
但是,每当执行此操作时,我都会发现自己必须在CSS中分配特定的顶部"值.因此div 1可能是top:50px,div 2将会是top:150px,而div 3将会是top:225px;
However, whenever I do this, I find myself having to assign specific "top" values in my CSS. So div 1 might be top:50px, div 2 would be top:150px, and div 3 would be top:225px;
是否有一种方法可以确保div继续在父级内部堆叠而无需分配顶部值和/或绝对位置?
Is there a way to make sure the divs continue to stack inside the parent without assigning top values and/or absolute positioning?
推荐答案
div
应该已经显示为块并占据了完整的行".这是一些HTML和CSS给出的示例,将其与您的代码进行比较:
A div
should already display as a block and take up a full "row". Here is some HTML and CSS to give an example, compare it to your code:
<div id="parent">
<div class="child">Foo</div>
<div class="child">Bar</div>
<div class="child">Baz</div>
</div>
这篇关于如何自动在父级内部垂直堆叠div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文