vue3 antdv a-datepicker 修改datepicker 的panel宽度,初始弹出一些正常,但再次弹出,宽度就再次变小的解决

1、展示页面的框架结构:

2、然后,我们上二张图对比一下:

图1-1

需要的效果图:

图1-2

对比一下图1-1与图1-2,我们就会发现图1-1中的农历,换行显示了,第二张是有效的。

3、我们修改样式,让其变成我们想要的样式:

<style lang="less" scoped>
  @width: 425px;

  .lua-date-picker-custom {
    background: none !important;

    .ant-picker-panel-container {
      width: @width;
      background: #fff !important;
      color: #000000 !important;
    }

    .ant-picker-panel {
      width: @width;
      border: 0px solid #000000 !important;
    }

    .ant-picker-header {
      width: @width;
      color: #000000 !important;
    }

    .ant-picker-content {
      width: @width - 20px;
    }

    .ant-picker-content th,
    td {
      color: #000000 !important;
    }

    .ant-picker-content td:hover > .ant-picker-cell-inner {
      background: #fff !important;
    }

    .ant-picker-cell:hover:not(.ant-picker-cell-in-view) .ant-picker-cell-inner,
    .ant-picker-cell:hover:not(.ant-picker-cell-selected):not(.ant-picker-cell-range-start):not(
        .ant-picker-cell-range-end
      ):not(.ant-picker-cell-range-hover-start):not(.ant-picker-cell-range-hover-end)
      .ant-picker-cell-inner {
      background: #fff !important;
    }

    .ant-picker-cell-inner {
      background: #fff !important;
    }

    .ant-picker-time-panel-column
      > li.ant-picker-time-panel-cell
      .ant-picker-time-panel-cell-inner {
      color: #000000 !important;
    }

    .ant-picker-time-panel-column
      > li.ant-picker-time-panel-cell-selected
      .ant-picker-time-panel-cell-inner {
      background: #fff !important;
    }

    .ant-picker-datetime-panel .ant-picker-time-panel {
      border-left: 1px solid #000000 !important;
    }

    .ant-picker-time-panel-column:not(:first-child) {
      border-left: 1px solid #000000 !important;
    }

    .ant-picker-ok {
      background: #fff !important;
      color: #fff !important;
    }

    .ant-btn-primary[disabled],
    .ant-btn-primary[disabled]:hover,
    .ant-btn-primary[disabled]:focus,
    .ant-btn-primary[disabled]:active {
      color: #fff;
      border: none;
      background: #fff !important;
      text-shadow: none;
      box-shadow: none;
    }

    .ant-picker-range-arrow::after {
      border-color: #c0c4cc #c0c4cc transparent transparent;
    }
  }
</style>

3、我们发现代码中感觉没有什么不对的地方,但是为什么会出现不太稳定的情况呢,初始加载是好的,然后再次退出Modal,再次进入Modal就变窄了,就是变长了一些,宽度变小,导致农历显示换行的情况。

4、然后我们把scoped去掉,就会发现竟然好了,这个scoped是局部的意思,然后是在Modal中显示出来的。

5、稳定的css的写法如下:

<style lang="less">
  @width: 425px;

  .lua-date-picker-custom {
    background: none !important;

    .ant-picker-panel-container {
      width: @width;
      background: #fff !important;
      color: #000000 !important;
    }

    .ant-picker-panel {
      width: @width;
      border: 0px solid #000000 !important;
    }

    .ant-picker-header {
      width: @width;
      color: #000000 !important;
    }

    .ant-picker-content {
      width: @width - 20px;
    }

    .ant-picker-content th,
    td {
      color: #000000 !important;
    }

    .ant-picker-content td:hover > .ant-picker-cell-inner {
      background: #fff !important;
    }

    .ant-picker-cell:hover:not(.ant-picker-cell-in-view) .ant-picker-cell-inner,
    .ant-picker-cell:hover:not(.ant-picker-cell-selected):not(.ant-picker-cell-range-start):not(
        .ant-picker-cell-range-end
      ):not(.ant-picker-cell-range-hover-start):not(.ant-picker-cell-range-hover-end)
      .ant-picker-cell-inner {
      background: #fff !important;
    }

    .ant-picker-cell-inner {
      background: #fff !important;
    }

    .ant-picker-time-panel-column
      > li.ant-picker-time-panel-cell
      .ant-picker-time-panel-cell-inner {
      color: #000000 !important;
    }

    .ant-picker-time-panel-column
      > li.ant-picker-time-panel-cell-selected
      .ant-picker-time-panel-cell-inner {
      background: #fff !important;
    }

    .ant-picker-datetime-panel .ant-picker-time-panel {
      border-left: 1px solid #000000 !important;
    }

    .ant-picker-time-panel-column:not(:first-child) {
      border-left: 1px solid #000000 !important;
    }

    .ant-picker-ok {
      background: #fff !important;
      color: #fff !important;
    }

    .ant-btn-primary[disabled],
    .ant-btn-primary[disabled]:hover,
    .ant-btn-primary[disabled]:focus,
    .ant-btn-primary[disabled]:active {
      color: #fff;
      border: none;
      background: #fff !important;
      text-shadow: none;
      box-shadow: none;
    }

    .ant-picker-range-arrow::after {
      border-color: #c0c4cc #c0c4cc transparent transparent;
    }
  }
</style>

只是把scoped给去掉了,就达到了我们的效果,其实就是全局样式的意思。

6、经过实测以后,我们发现不管是将css放到主页面,还是放到Modal中,一定要去掉scoped才行,否则不生效。

  • 8
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值