
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
* {padding: 0; margin: 0;}
.wrap {width: 200px; height: 200px; border: 10px solid yellow; padding: 10px; margin: 50px; background: red; position:relative;}
.a {width: 50px; height: 50px; background: black; position: absolute; top:0; right: 0; z-index: 9999; float: left;}
img {position: absolute; top:0; left: 0; z-index: 999;}
</style>
</head>
<body>
<div class="wrap">
<img style="width:100%; height:100%;" src="v10.jpg" alt="">
<div class="a"></div>
</div>
<!--
z-index无论设置多高都不起作用情况
这种情况发生的条件有三个:
1、父标签 position属性为relative;
2、问题标签无position属性(不包括static);
3、问题标签含有浮动(float)属性。 -->
</body>
</html>
https://www.w3.org/TR/2011/RE...
所以 position 为 absolute 会让 float 无效。
其次,看渲染顺序
可以看到,float 在中间,z-index 正值的 absolute 在最后,所以总会盖住 float。