我希望几个div能够排列在一起形成一条线,但也允许它们重叠。
我的目标是创建一个时间轴,其中每个事件都用一个div表示,这些事件可以相互重叠。
我的想法是给每个div相同的顶部位置,递增的z-index和左侧位置(根据事件发生的时间)。稍后,我会通过鼠标悬停事件弹出单个div以可视化重叠。
我的问题是所有的div都被放在了下一个div下面。虽然通过调整顶部属性,我可以使它们水平对齐,但我没有看到模式。
<div class="day">
<div style="top: 35px; left: 200px; background-color: red; height: 50px; width:24px; z-index: 1; position: relative;"> </div>
<div style="top: 35px; left: 220px; background-color: green; height: 50px; width:24px; z-index: 2; position: relative;"> </div>
<div style="top: 35px; left: 225px; background-color: blue; height: 50px; width:48px; z-index: 3; position: relative;"> </div>
</div>
如果我使用绝对定位,元素会飞出包围它们的 div,并且绝对定位到页面的某个位置。