css - 子与父之间的显示元素
问题描述
我正在尝试在两个嵌套元素之间呈现一个元素。这可能最好用一个例子来解释:
#parent {
position: fixed;
top: 0;
left: 0;
width: 200px;
height: 200px;
z-index: 0;
background-color: red;
}
#child {
position: fixed;
top: 50px;
left: 50px;
width: 100px;
height: 100px;
z-index: 2;
background-color: blue;
}
#other {
position: fixed;
top: 25px;
left: 25px;
width: 50px;
height: 50px;
z-index: 1;
background-color: green;
}
<div id="parent">
<div id="child"></div>
</div>
<!-- I want to have this element in between the "parent" and "child". -->
<div id="other"></div>
在这种情况下,我希望将绿色(“#other”)元素呈现在(z 深度方向)红色父元素(“#parent”)和蓝色子元素(“#child”)之间。换句话说,我希望蓝色元素位于顶部。
据我了解,由于元素是嵌套的,因此使用 CSS 的 z 深度(就像我尝试的那样)是不可能的,但我似乎无法找到不同的方式。
如果可能的话,我想保持 HTML 的原样,并完全在 CSS 中完成。
提前致谢!
解决方案
推荐阅读
- javascript - 将静态文本复制到剪贴板?
- installation - 在 appium-chromedriver@4.0.0 安装脚本失败
- c - mingw 下的 fread() 无法正常工作
- php - 具有命名空间问题的 SimpleXml
- java - java.lang.SecurityException:创建 JAR 到 OSGI 包后,Manifest 主要属性的签名文件摘要无效
- sql - 每第n个字符后加逗号,但不能在单词内
- google-bigquery - Power bi 和 bigquery
- vb6 - VB6 在 XMLHttp 请求中包含刻度线
- ruby-on-rails - 使用rails中的复选框检查未定义的方法
- android - 如何在 onDataChange 方法之外获取 arrayList 值,使其不会激活 startActivity