一、html代码html
<div v-if="maskVisible" class="mask_layer" @click="关闭事件">
<div class="dialog_div" @click.stop><-- @click.stop 不允许触发父级事件 -->
<div style="display: flex; justify-content: center; align-items: center;width: 100%;height: 100%;">
内容
</div>
</div>
</div>
注:不触发父级事件的方法可参考:https://www.cnblogs.com/ymm-notes-blog/p/11969358.html
二、css
.mask_layer {
position: absolute;
left: 0;
top: 0;
background: rgba(0, 0, 0, 0.4);
width: 100%; /*宽度设置为100%,这样才能使隐藏背景层覆盖原页面*/
height: 100%;
filter: alpha(opacity=60); /*设置透明度为60%*/
/*opacity: 0.6;*/ /*非IE浏览器下设置透明度为60%*/
z-Index: 9999;
.dialog_div {
position: absolute;
width: 40%;
height: 50%;
top: 25%;
left: 25%;
/*background-color: #fff;*/
/*cursor: pointer;*/ /* 鼠标类型 */
z-Index: 99999;
}
}