gpt4 book ai didi

html - CSS 位置 child 在它的 parent 之下

转载 作者:搜寻专家 更新时间:2023-10-31 08:32:46 25 4
gpt4 key购买 nike

是否可以将子元素 (C) 置于其父元素 (B) 之下,并置于 B 的邻居元素 (C) 之上?

描述起来有点难,可以看例子here .

问题是将蓝色 div.inner 放在红色 div.neighbor 和绿色 div.outer 之下。

举例说明:

enter image description here

HTML代码:

 <div class="neighbor">&nbsp;</div>
<div class="outer">
<div class="inner"></div>
</div>

CSS 代码:

.neighbor{
background-color: red;
height: 500px;
width: 500px;
}

.outer{
background-color: green;
width: 300px;
height: 300px;
position: fixed;
top: 0px;
left: 0px;
}

.inner{
background-color: blue;
width: 100px;
height: 100px;
position: fixed;
top: 0px;
left:250px;
}

最佳答案

JsFiddle

HTML:

<div class="red"></div>
<div class="green"></div>
<div class="blue"></div>

CSS:

.red {
background-color: red;
height: 500px;
width: 500px;
z-index: 1;
}

.green {
background-color: green;
width: 300px;
height: 300px;
position: fixed;
top: 0px;
left: 0px;
z-index: 3;
}

.blue {
background-color: blue;
width: 100px;
height: 100px;
position: fixed;
top: 0px;
left: 250px;
z-index: 2;
}

关于html - CSS 位置 child 在它的 parent 之下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19180281/

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