修改el-message-box的样式但是customClass重写样式无用

用this.$confirm固定高度是420px,在移动端显示太宽,需要重新修改el-message-box的样式。

      this.$confirm('You are about to leave the platform', 'Tips', {
        confirmButtonText: 'continue visit',
      dangerouslyUseHTMLString: true,
        cancelButtonText: 'Cancel',
      showCancelButton:false,
        type: 'warning'
      }).then(() => {

      console.log("success")
    }).catch(() => {

      });

当采用customClass之后,在页面css中重新设置宽度,但起不到一点作用,
在这里插入图片描述在这里插入图片描述
在这里插入图片描述

注意1

样式需要写在scoped之外,表示全局样式,不局限在页面中,于是有了三种写法,直接重写el-message-box、定义类text、两个一起定义。

第一种

<style>
  .el-message-box{
    width: 325px !important;
    margin: 100px 0 !important;
  }
</style>

第二种

<style>
.text{
    width: 325px !important;
    margin: 100px 0 !important;
  }
  </style>

第三种

<style>
.el-message-box .text{
    width: 325px !important;
    margin: 100px 0 !important;
  }
  </style>

但是,第一种、第二种可以实现重定义el-message-box的样式在这里插入图片描述

第三种就不行了,不知道为啥,不理解!
在这里插入图片描述

注意2

限制移动端的el-message-box宽度,而PC中的el-message-box宽度不变,用到media,“可以指定一个媒体查询和一个 CSS 块,当且仅当该媒体查询与正在使用其内容的设备匹配时,该 CSS 块才能起作用。”

<style>
@media (max-width: 757px){
  .el-message-box{
    width: 300px !important;
    margin: 100px auto !important; /* 水平居中 */
  }
}
</style>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值