css - 如何将转换后的元素保留在另一个元素后面?
问题描述
.container {
width: 100px;
height: 100px;
font-size: 100px;
}
.background {
color: red;
width: 100%;
height: 100%;
margin-bottom: -100%;
transform: rotate(90deg);
}
.foreground {
color: blue;
width: 100%;
height: 100%;
}
<div class="container">
<div class="background">B</div>
<div class="foreground">F</div>
</div>
这个例子也在这里:https://jsfiddle.net/jasajona/vmzfgkcb/ 如何将转换后的背景 div 保持在前景后面?找到了几个示例,但它们似乎不适用于这种情况。
解决方案
只需将 a 添加position: relative
到两个图层,然后使用对它们进行排序z-index
(如果position
未设置,则考虑它static
并且static
不考虑 z-indexes)
.container {
width: 100px;
height: 100px;
font-size: 100px;
}
.background {
color: red;
width: 100%;
height: 100%;
margin-bottom: -100%;
transform: rotate(90deg);
position: relative;
z-index: 1;
}
.foreground {
color: blue;
width: 100%;
height: 100%;
position: relative;
z-index: 2;
}
<div class="container">
<div class="background">B</div>
<div class="foreground">F</div>
</div>
推荐阅读
- pycharm - PyCharm Professional 2020.2 - 缺少“运行任何东西”选项?
- python-3.x - 如何像在命令行上一样在 VSCode 中运行单个测试?
- node.js - 未设置安全 cookie
- swift - 如何在 SwiftUI 中关闭两个视图
- lua - 罗技 g hub 脚本在我发布后立即停止
- r - 使用 rms::Predict 遍历列
- python - 如何使用 PyYaml 或 Ruamel.yaml 仅转储带有 flow_style 的列表
- heroku - 如何从 Azure 发布管道将 React JS 构建文件夹部署到 Heroku 服务器
- python - 尝试使用 openslide 和 py_wsi 时出错
- python - 为什么 float() 不浮动?