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

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

时间:2024-08-14 17:56:56浏览次数:10  
标签:datepicker picker antdv cell ant 宽度 fff important 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才行,否则不生效。

标签:datepicker,picker,antdv,cell,ant,宽度,fff,important,panel
From: https://blog.csdn.net/jwbabc/article/details/141182892

相关文章

  • 每日一题:Leetcode-662 二叉树最大宽度
    力扣题目解题思路java代码力扣题目:给你一棵二叉树的根节点 root ,返回树的 最大宽度 。树的 最大宽度 是所有层中最大的 宽度 。每一层的 宽度 被定义为该层最左和最右的非空节点(即,两个端点)之间的长度。将这个二叉树视作与满二叉树结构相同,两端点间会出现一些......
  • react项目中不同宽度断点处理
    当react项目中,你需要通过判断当前屏幕宽度改变,对不同宽度断点进行不同的处理,例如,当屏幕宽度缩小至768px及以下时,需要将某一个属性值改变,或者是当屏幕宽度缩小或者放大到某一宽度时,需要调用某个方法使用window.matchMedia()监听媒体查询importReact,{useEffect}from'react'......
  • echarts图标如何自适应宽度
    echarts图标直接设置宽度100%会默认魏100px,需要自适应方法如下图标html<el-col:span="8"><divid="userNianling_three"style="width:100%;height:500px;"/>......
  • FastReport不通过触发文本框宽度改变字体大小
    FastReport无法根据字数超出文本框高度而去改变字体大小,所以写了以下方法简单提供一个思路1privatevoidText_AfterData(objectsender,EventArgse)2{3doublemaxHeight=337;4doubletxtHeight=((TextObject)sender).Height;5......
  • 解决Leaflet地图初始化后更改容器宽度,新增部分瓦片没有请求问题
    当使用Leaflet初始化地图并在后续操作中动态更改地图容器的宽度时,可能会出现地图新增加的部分没有请求瓦片的情况。这是因为Leaflet在初始化时计算并缓存了地图的尺寸,当容器的尺寸发生变化时,地图没有自动刷新来适应新的尺寸。为了解决这个问题,需要在动态更改容器宽度后调用L......
  • CPU指令集——bayer抽取r、g、b三通道(含镜像)-宽度为16或32整数倍版本
    #include<intrin.h>//forsse#include<string.h>//formemcpyenumBayerFormat{bayerRG,bayerGR,bayerBG,bayerGB};enumMirror{mirrorNo,//不镜像mirrorTB,//上下镜像mirrorLR,//左右镜像......
  • 自定义Obsidian输入栏宽度
    自定义Obsidian输入栏宽度以Obsidian的主题Minimal为案例,进行输入栏宽度的调整;若是没有此主题Minimal,通过设置找到外观后,主题那栏点击管理输入Minimal进行下载(这个主题还是挺不错的);点击左下角设置,选择外观,点击文件夹,找到对应的.css文件文件夹的......
  • 如何解决el-select-dropdown的宽度过长
    问题:由于名称有的特别长,导致下拉框的宽度也跟着边长,导致页面效果不好。解决办法:1、首先设置el-select的属性popper-append-to-body为false:不将下拉弹出框插入至body元素<el-selectv-model="listQuery.company":popper-append-to-body="false"class="input-select"filter......
  • Tkinter 的带有 wrap=none 的文本无法水平滚动超过可见行的宽度
    当我注意到如果长行不可见时,ScrolledText小部件的水平滚动条将消失时,我一直在修改PAGE滚动小部件的实现。事实证明这与水平滚动条无关,是原始Tk行为:pathNamexview返回包含两个元素的列表。每个元素都是0到1之间的实数分......
  • 如何使用OpenCV测量两条相交绳索的宽度和角度?
    下面第一张图是原始图像,显示了一个网络。网中的绳索有两种类型:粗绳和细绳。需要通过OpenCV区分哪些是粗绳,哪些是细绳,并分别测量它们的角度。importcv2importnumpyasnpdefmeasure_rope_width(image):gray=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)......