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

标签 html css css-position

是否可以将子元素 (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/

相关文章:

html - 如何在 html 中创建自动调整列,其中无论列数如何都不会出现水平滚动条

javascript - 重新定位按钮文本不可点击

html - 中心 div 宽度取决于内容

javascript - 位置 : sticky is not working with top property?

html - 围绕字符串的中间字符居中文本

css - 为什么当浏览器调整大小时,下面页面中的 html 控件会换行

html - :active is behaving weird 上的绝对位置

html - 将绝对元素居中,直到没有 js 的范围

javascript - 单击浏览器 html 页面中的链接时显示 VB6 表单

javascript - 卡住 TH 标题和滚动数据