將一個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>
</body>
</html>