首先你得有兩個層:
<style type="text/css">
.div_1{
width:100px;
height:100px;
background-color:blue:
}
.div_2{ //如果想讓您的子層跟隨父層且透明,這樣就可以了
position: absolute;
width: 1000px;
height: 130px;
z-index:999;
background: rgba(67, 114, 138, 0.5);
margin-left: 450px;
}
.div_2{ //如果想讓您的子層不跟隨父層且透明,這樣就可以了
position:fixed;
width: 1000px;
height: 130px;
background: rgba(67, 114, 138, 0.5);
margin-left: 450px;
left:0px;
top:0px;
}
</style>
<body>
<div class="div_1">
這是父層
</div>
<div class="div_2">
這裏是透明的
</div>
</body>
小結:
(
position這個屬性一共有四個 選項:static、relative、absolute、fixed。
fixed:
位置被設置爲 fixed 的元素,可定位於相對於瀏覽器窗口的指定座標。此元素的位置可通過 "left"、"top"、"right" 以及"bottom" 屬性來規定。不論窗口滾動與否,元素都會留在那個位置。
):