答案:使用CSSz-index属性
您可以将CSSposition属性与该z-index属性结合使用,以将单个对象覆盖div在另一个div元素上。的z-index属性来确定用于定位元素的堆叠顺序(即元件,其位置值是中的一个absolute,fixed或relative)。
让我们尝试以下示例以了解其基本工作原理:
例试试这个代码»
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CSS Overlaying One DIV over Another DIV</title>
<style>
.container{
width: 200px;
height: 200px;
position: relative;
margin: 20px;
}
.box{
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
opacity: 0.8; /* for demo purpose */
}
.stack-top{
z-index: 9;
margin: 20px; /* for demo purpose */
}
</style>
</head>
<body>
<div class="container">
<div class="box" style="background: red;"></div>
<div class="box stack-top" style="background: blue;"></div>
</div>
</body>
</html>
如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h61135.shtml