CSS中div覆盖另⼀个div 将⼀个div覆盖在另⼀个div上有两种⼿段:⼀是设置margin为负值,⼆是设置绝对定位。
可以根个⼈情况设置z-index的值
1->position 为absolute的情况
<html>
<head>
<style>
#div1{position:absolute;width:300px;height:300px;background:#ccc;}
#div2{position:absolute;left:0;top:0;width:200px;height:200px;background:red;filter:alpha(opacity=50);}
</style>
</head>
<body>
<divid="div1">这⾥是div1的内容
<divid="div2"></div>
</div>
</body>
</html>
2->⽤margin为负的操作
<html>
<head>
<style>
#div1 { position:relative; width:300px; height:300px; background:#ccc;}
#div2 { position:relative; left:0; top:0;margin-top:-15px; width:200px; height:200px; background:red;filter:alpha(opacity=50);}    </style>
</head>
<body>
<divid="div1"> 这⾥是div1的内容
<divid="div2"></div>div中的div居中
</div>
</body>
</html>