html - 为什么 z-index 不与这两个正方形重叠?
问题描述
大家好,我有这个代码
HTML:
<div class="container">
<div class="s1"></div>
<div class="s2"></div>
</div>
CSS:
.container{
border:1px solid;
height:300px;
width:300px;
}
.s1{
position:relative;
z-index:1;
background-color:red;
height:30px;
width:30px;
}
.s2{
position:relative;
z-index:2;
background-color:green;
height:90px;
width:90px;
}
我希望绿色方块与红色方块重叠,但这不起作用。有人可以解释我为什么吗?谢谢。
解决方案
他们都是position: relative
。尝试设置为position: absolute;
推荐阅读
- python - 使用 Python 下载 PDF 和跟踪下载
- python - 如何在熊猫数据框中连接嵌套数组
- azure - Azure:New-AzRoleAssignment 输入字符串的格式不正确 - 双重解析出错...没有任何数字
- javascript - Retrieve elements in js from a json object
- c++ - 如何实现_mm_and_ps?
- c# - C# SOAP 服务配置问题
- git - 我可以从 git 浏览 github 存储库吗?
- python - 应用这两个数据帧时数据帧 loc 错误
- javascript - 使用反应,我如何在点击时隐藏表格行?
- python - Keras LSTM 训练和验证数据中的时间步长顺序