<!-- * @Description: * @Autor: renchao * @LastEditTime: 2023-07-20 13:40:32 --> <template> <div class="model"> <div class="mask">123</div> <div class="model-dialog"> <div class="model-header"> <span>提示</span> <a href="javascript:;" class="icon-close"></a> </div> <div class="model-body"> <div class="body">这是条消息</div> </div> <div class="model-footer"> <button class="btn">确认</button> </div> </div> </div> </template> <style scoped lang='scss'> //css部分 .mask { position: fixed; //这里用固定定位,后面设置动画时才不受影响 top: 0; height: 100%; width: 100%; background-color: rgba(167, 165, 165, 0.486); opacity: 0.5; z-index: 9; } .model-dialog { position: absolute; //让弹框居中显示 top: 50%; left: 50%; transform: translate(-50%, -50%); background-color: #fff; border-radius: 12px; width: 600px; height: 300px; border: 1px solid #f5f5f5; overflow: hidden; z-index: 10; //这里注意层级要比mask大,覆盖它 } .model-header { position: relative; height: 50px; padding-left: 10px; padding-top: 10px; font-size: 20px; line-height: 50px; background-color: #f5f5f5; border-bottom: 1px solid rgb(177, 176, 176); } .model-body { height: 150px; line-height: 150px; font-size: 28px; text-align: center; background-color: #fff; } .model-footer { background-color: #f5f5f5; height: 100px; text-align: center; line-height: 100px; } .btn { width: 180px; height: 40px; border-radius: 8px; background-color: rgb(180, 103, 103); color: #fff; font-size: 18px; border: none; } .icon-close { position: absolute; //如果不加绝对布局,图表显示不出来 background-color: pink; right: 15px; top: 16px; width: 30px; height: 30px; z-index: 10; //background: url("../assets/icon-close.png") no-repeat; background-size: contain; } </style>