html - css / html中z轴上的父级高于子级
问题描述
我有一个 div(父级)和另一个 div 在父级(子级)中,我想将子级隐藏在父级后面。
编辑:我会尝试更好地解释,所以我谈论z轴,但如果我做类似的事情:
.parent {
z-index: 10;
}
.child {
z-index: 0;
}
它不工作。所以我问你一个问题:我的孩子怎么能在z轴上在我父母的下方?
.parent {
width: 200px; height: 200px;
background-color: red;
}
.child {
width: 100px; height: 100px;
background-color: blue;
}
<div class="parent">
<div class="child"></div>
</div>
解决方案
如果您将使用 z-index. z-index仅适用于定位元素(位置:绝对、位置:相对或位置:固定)。
.parent {
background-color: red;
height:100px;
width:100px;
}
.child {
background-color: blue;
height:50px;
width:50px;
position:relative;
z-index: -1;
}
<div class="parent">
<div class="child"></div>
</div>
推荐阅读
- java - 将字符串格式化为 BigDecimal
- javascript - 在javascript中获取此字符串的最简单方法是什么
- javascript - AR.JS 自定义标记
- sql - 根据条件过滤数据
- colors - 如何在 CGAL 中更改网格边界顶点的颜色属性
- java - JButton 没有出现在 JFrame 上
- r - mutate_impl(.data, dots) 中的错误:找不到绑定:
- java - 如何使用 Spring RestTemplate 在 GET 调用中传入 Java 列表以在控制器中使用
- kubernetes - 如何添加安全性以在 k8s 中运行 Ignite Web 控制台
- typescript - 使用 redux 设置嵌套在不可变映射中的属性的值