情景类似于:
<div class="a">
hello this is my text
<div class="x">
</div>
</div>
我需要在div a上显示div x。 我面临的问题是当我包含文本时,div位于下一行。
我该怎么做?
答案 0 :(得分:0)
我想以下代码会为您提供所需的输出:
.a{
position:relative;
}
.x{
position:absolute;
top:0;
}
<div class="a">
hello this is my text
<div class="x">
akejfhlaqfhe
</div>
</div>
答案 1 :(得分:0)
为了在另一个div上“显示”div,你需要使用position:相对于父(.a)和绝对位置到child(.x)
.a .x {
position:absolute;
background:#e74c3c;
opacity:.5;
left:0; top:0; bottom:0; right:0;
}