修改element-ui中el-calendar(日历)的样式

效果图如下:

在这里插入图片描述

<template>
  <div class="dashboard-container">
    <el-card style="width: 350px; height: auto; border-radius: 8px">
      <div class="custom-style">
        <p class="new-data">{{ newDate }}</p>
        <el-calendar ref="calendar" v-model="value" />
      </div>
    </el-card>
  </div>
</template>
<script>

export default {
  name: 'Dashboard',
  data() {
    return {
      value: new Date()
    }
  },
  computed: {
    newDate() {
      return this.formatDate(this.value)
    }
  },
  methods: {
    formatDate(value) {
      const date = new Date(value)
      const year = date.getFullYear()
      const month = date.getMonth() + 1
      const day = date.getDate()
      return `${year}${month < 10 ? '0' + month : month}${
        day < 10 ? '0' + day : day
      }`
    }
  }
}
</script>

<style lang="scss">

// 自定义样式
.custom-style {
    .new-data {
        position: absolute;
        margin: 0;
        line-height: 26px;
    }

    .el-calendar__title {
        opacity: 0;
    }

    // 上个月、下个月按钮样式
    .el-button-group>.el-button:first-child:before {
        content: "";
        display: inline-block;
        width: 6px !important;
        height: 6px !important;
        border: transparent;
        border-top: 1px solid #6e6c6c;
        border-right: 1px solid #6e6c6c;
        transform: rotate(-135deg);
        /* 可根据需要调整间距 */
    }

    .el-button-group>.el-button:last-child:before {
        content: "";
        display: inline-block;
        width: 6px !important;
        height: 6px !important;
        border: transparent;
        border-top: 1px solid #6e6c6c;
        border-right: 1px solid #6e6c6c;
        transform: rotate(45deg);
    }

    .el-button-group>.el-button:not(:first-child):not(:last-child) {
        color: #444444;
    }

    .el-button-group>.el-button:first-child span,
    .el-button-group>.el-button:last-child span {
        display: none;
    }

    .el-button-group>.el-button:not(:last-child) {
        margin-right: -15px;
    }

    // 去除文字
    .el-button-group>.el-button:not(:first-child):not(:last-child) {
        span {
            display: none;
        }
    }

    .el-button-group>.el-button {
        border: 0;
        background: transparent;
    }

    .el-calendar-table__row td {
        // 去掉边框
        border: none !important;

        // 缩小高度
        .el-calendar-day {
            height: 32px;
            line-height: 18px;
            // 设置居中
            text-align: center;
        }
    }

    // 自定义选中、悬浮颜色
    .el-calendar-table .el-calendar-day:hover {
        color: #fff;
        background-color: #ff5e78 !important;
    }

    .el-calendar-table .is-today {
        color: #303133;
    }

    .el-backtop,
    .el-calendar-table td.is-today {
        color: #ff5e78;
    }

    .el-calendar-table .is-selected {
        color: #fff !important;
        background-color: #ff5e78 !important;
    }

    .el-calendar__header {
        display: flex;
        justify-content: space-between;
        padding: 0px 20px;
        border: none;
    }
}
</style>

  • 6
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

吃葡萄不吐葡萄皮嘻嘻

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值