定义和用法
zIndex 属性设置元素的堆叠顺序。
该属性设置一个定位元素沿 z 轴的位置,z 轴定义为垂直延伸到显示区的轴。如果为正数,则离用户更近,为负数则表示离用户更远。
提示和注释
注释:元素可拥有负的 z-index 属性值。
注释:Z-index 仅能在定位元素上奏效。
备注:当你定义的CSS中有position属性值为absolute、relative或fixed,用z-index此取值方可生效。范例:
<html>
<head>
<style type="text/css">
#img1
{
position:absolute;
left:0px;
top:0px;
z-index:-1
}
</style>
<script type="text/javascript">
function changeStackOrder()
{
document.getElementById("img1").style.zIndex="1";
}
</script>
</head>
<body>
<h1>This is a Heading</h1>
<img id="img1" src="bulbon.gif" width="100" height="180">
<p>Default z-index is 0. Z-index -1 has lower priority.</p>
<input type="button" οnclick="changeStackOrder()"
value="Change stack order" />
</body>
</html>
来源:http://www.w3school.com.cn/jsref/prop_style_zindex.asp