CSS z-index 不起作用(绝对位置) [英] CSS z-index not working (position absolute)

查看:43
本文介绍了CSS z-index 不起作用(绝对位置)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将黑色 div(相对)置于第二个黄色(绝对)之上.黑色 div 的父元素也有一个绝对位置.

#relative {位置:相对;宽度:40px;高度:100px;背景:#000;z-索引:1;边距顶部:30px;}.绝对{位置:绝对;顶部:0;左:0;宽度:200px;高度:50px;背景:黄色;z-索引:0;}

<div id="relative"></div>

<div class="absolute" style="top: 54px"></div>

预期结果:

解决方案

移除

z-index:0;

来自.absolute.

在此处更新了小提琴.

I am trying to make the black div (relative) above the second yellow one (absolute). The black div's parent has a position absolute, too.

#relative {
	position: relative;
	width: 40px;
	height: 100px;
	background: #000;
	z-index: 1;
	margin-top: 30px;
}
.absolute {
	position: absolute;
	top: 0; left: 0;
	width: 200px;
	height: 50px;
	background: yellow;
	z-index: 0;
}

<div class="absolute">
    <div id="relative"></div>
</div>
<div class="absolute" style="top: 54px"></div>

Expected Result:

解决方案

Remove

z-index:0;

from .absolute.

Updated fiddle here.

这篇关于CSS z-index 不起作用(绝对位置)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆