方法一:
<div class="bg" >//遮罩層 <div class="point"> <div class="pop"></div> //內容區 </div> </div>
.bg{ width:100%; height:100%; left:0; top:0; position:fixed; background:rgba(0,0,0,0.3); } .point{ position:absolute; left:50%; top:50%; } .pop{ width:500px; height:500px; position:absolute; left:-250px; top:-250px; border:2px solid red; }
方法二:margin負邊距法
<div class="bg"> <div class="pop"></div> </div>
.bg{ width:100%; height:100%; left:0; top:0; position:fixed; background:rgba(0,0,0,0.3); } .pop{ width:500px; height:500px; position:absolute; left:50%; top:50%; left:-250px; top:-250px; border:2px solid red; }
方法三:transform屬性
<div class="bg"> <div class="pop"></div> </div>
.bg{ width:100%; height:100%; left:0; top:0; position:fixed; background:rgba(0,0,0,0.3); } .pop{ width:500px; height:500px; position:absolute; left:50%; top:50%; transform: translate(-50%,-50%); border:2px solid red; }