element dialog 垂直水平居中显示

原文:https://blog.csdn.net/zhangfeng1329972027/article/details/120900237

先将dialog放到body的下层,保证自己写的样式相对于视口区域生效。element dialog文档中有个append-to-body属性,将其设置为true,会将dialog扔到body下面。
再设置一个自定义dialog的class

<el-dialog title="标题" custom-class="selfDialog" :visible.sync="dialogVisible" :append-to-body="true">
  <div class="content" ></div>
</el-dialog>

然后再给selfDialog给样式,注意dialog已经被扔到body下面,在组件less里嵌套写样式不会生效,要在组件的原有style外再加个标签。content的这个class也是在body下面。

<style>
  .selfDialog{
    position:absolute;
    left:50%;
    top:50%;
    transform: translate(-50%,-50%);
    height:90%;
    width:80%;
    margin-top:0!important;
  }
  .content{
    display:flex;
    align-items: center;
    justify-content: center;
    width:95%;
    height:90%;
  }
</style>

<style lang="less"  scoped>
  /*自己组件的样式*/
</style>

posted on   苏舒  阅读(935)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示