gpt4 book ai didi

html - 具有相对和绝对定位的元素

转载 作者:太空宇宙 更新时间:2023-11-04 06:54:57 25 4
gpt4 key购买 nike

我想渲染一些相对相邻但绝对位于其他所有元素之上的元素。可以看到here对于我想要渲染的内容和下面的 fiddle (或 this codepen ),我试图让它工作。谢谢!

.row {
display: flex;
}

.box {
height: 100px;
width: 100px;
background: yellow;
border: 2px solid red;
margin: 5px;
}

.tallBox {
height: 150px;
width: 100px;
background: orange;
border: 2px solid green;
margin: 5px;
}

.bar {
height: 100px;
width: 442px;
background: pink;
border: 2px solid red;
margin: 5px;
}

.group {
display: flex;
// position: absolute;
}

.gap {
height: 100px;
}
<h2>Proposal: </h2>
<img src="https://i.imgur.com/n1juYRj.png">
<div class="gap"></div>

<h2>Current rendering without any changing any position properties:</h2>
<section class="row">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</section>
<section class="row">
<div class="bar"></div>
</section>

<div class="gap"></div>

<h2>Attempt:</h2>
<section class="row special">
<div class="box"></div>
<div class="group">
<div class="tallBox"></div>
<div class="tallBox"></div>
</div>
<div class="box"></div>
</section>
<section class="row">
<div class="bar"></div>
</section>

最佳答案

您或许可以考虑负边距并避免使用 position:absolute

.row {
display: flex;
}

.box {
height: 100px;
width: 100px;
background: yellow;
border: 2px solid red;
margin: 5px;
}

.tallBox {
height: 150px;
width: 100px;
background: orange;
border: 2px solid green;
margin: 5px;
margin-bottom:-50px;
}

.bar {
height: 100px;
width: 442px;
background: pink;
border: 2px solid red;
margin: 5px;
}

.group {
display: flex;
z-index:2;
}

.gap {
height: 100px;
}
<section class="row special">
<div class="box"></div>
<div class="group">
<div class="tallBox"></div>
<div class="tallBox"></div>
</div>
<div class="box"></div>
</section>
<section class="row">
<div class="bar"></div>
</section>

关于html - 具有相对和绝对定位的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52543713/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com