html - Z-index 不适用于父(相对)子(绝对)元素
问题描述
我试图让黑盒子出现在椭圆形元素(父级)的后面。因此,我决定使用z-index
,将父级的值设置为高于子级的值。但是,孩子仍然出现在父母之上。我通过将孩子设置z-index
为 -1 并z-index
从父母那里删除属性来解决这个问题。但我不明白为什么会这样,如果我想将z-index
属性保留在父级中怎么办?
这是我的 HTML:
<div id="x">
<div id="y"> </div>
</div>
这是我的CSS:
#x{
position: relative;
margin-top:40px;
height:400px;
width:250px;
border-radius: 40%;
margin-left: 30%;
background: linear-gradient(to bottom, #f5e050 78%, #517693 0%);
z-index:9999;
}
#y{
height: 5%;
width: 15%;
position: absolute;
top:97%;
left:36%;
background-color:black;
z-index: 1;
}
解决方案
推荐阅读
- excel - 不同的行自动过滤
- android - 当我将项目从 SDK 版本 28 设置为目标 SDK 版本 29 时,WebView 无法正常工作
- snmp - 使用另一个对象的语法定义 OBJECT-TYPE
- python - 删除函数和标签
- java - Application Insights - Java 应用程序中未跟踪依赖关系
- android - 什么是 Expo React-native 中的 DangerZone
- python - 如何每 3 个选择的元素中的 10 个元素对 numpy 数组进行二次采样
- javascript - 导航到另一条路线时重新加载数据而不刷新组件
- image-processing - 两幅图像的RGB直方图之间的欧几里得距离
- django - 部署到 Heroku 后如何删除“OperationalError at / no such table: subreddit_subreddit”?