首页 > 解决方案 > CSS:如何将一个 div 移到另一个上方?

问题描述

我有两个 div,A 和 B。我想使用 CSS 将元素 B 放在元素 A 之上。如果需要,我可以在父 div 中扭曲它们。我尝试了几件事(浮动,垂直对齐),但没有成功。

我有的:

一个

我想要的是:

一个

任何想法?谢谢

标签: css

解决方案


用容器中的 2 个文本 div 试试这个

body {
  font: 400 16px/1.5 sans-serif;
}
.text-wrap {
  position: relative;
}
.text-1 {
  position: absolute;
  top: 1.5em; /* same as line-height */
}
.text-2 {
  position: absolute;
  top: 0;
}

<div class="text-wrap">
    <div class="text-1">
        AAA
    </div>
    <div class="text-2">
        BBB
    </div>
</div>

推荐阅读