堆叠DIV在彼此的顶部? [英] Stacking DIVs on top of each other?

查看:180
本文介绍了堆叠DIV在彼此的顶部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以堆叠多个DIV,例如:

Is it possible to stack up multiple DIVs like:

<div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>

这样所有内部DIV都有相同的X和Y位置?默认情况下,它们都在彼此之下,将Y位置增加到上一个DIV的高度。

So that all those inner DIVs have the same X and Y position? By default they all go below each other increasing the Y position by the height of the last previous DIV.

我有一种感觉某种浮动或显示或其他伎俩bite?

I have a feeling some sort of float or display or other trick could bite?

编辑:父DIV有位置相对,所以,使用位置绝对似乎不工作。

The parent DIV has position relative, so, using position absolute does not seem to work.

推荐答案

然后定位外部div,然后使用绝对位置内部div。

Position the outer div however you want, then position the inner divs using absolute. They'll all stack up.


<style type="text/css">
.inner {
  position: absolute;
}
</style>

<div class="outer">
   <div class="inner">1</div>
   <div class="inner">2</div>
   <div class="inner">3</div>
   <div class="inner">4</div>
</div>

这篇关于堆叠DIV在彼此的顶部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆