z-index在css中怎么用?

z-index在css中怎么用?

http://zhidao.baidu.com/link?url=2s0rL4JTS-KKvEiB7IbwTBO4yuK_eth79lsm9w3qcZMgd8npCkaklqvuV1aIXGVpokv81w-wTfBszMlcqZImLa

当你定义的CSS中有position属性值为absolute、relative或fixed,

用z-index此取值方可生效。
此属性参数值越大,则被层叠在最上面。
例子:
<html>
<head>
<style>
.z1,.z2,.z3{position:absolute;width:200px;height:100px;padding:5px 10px;color:#fff;text-align:right;}
.z1{z-index:1;background:#000;}
.z2{z-index:2;top:30px;left:30px;background:#C00;}
.z3{z-index:3;top:60px;left:60px;background:#999;}
</style>
</head>
<body>
<div class="z1">z-index:1</div>
<div class="z2">z-index:2</div>
<div class="z3">z-index:3</div>
</body>
</html>
上面三个CSS,将根据z-index的值决定谁在最上层!


你可能感兴趣的:(z-index在css中怎么用?)