修改原生的<input type=“datetime-local“>样式

效果

在这里插入图片描述

基础样式

<input type="datetime-local" class="custom-datetime">
input[type="datetime-local"] {
  /* 重置默认样式 */
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none; // 禁用浏览器默认样式
  
  /* 自定义基础样式 */
  width: 200px;
  height: 30px;
  background: rgba(14, 20, 28, 1);
  color: #fff;
  border: 1px solid #7ad0e5;
  border-radius: 4px;
  padding: 5px 10px;
  outline: none;
  font-family: system-ui;
    /* 鼠标交互 */
  transition: all 0.3s ease;
  &:hover {
    border-color: #9adcf0;
    box-shadow: 0 0 8px rgba(122, 208, 229, 0.3);
  }
  
  &:focus {
    border-color: #4ec3e0;
    box-shadow: 0 0 12px rgba(122, 208, 229, 0.5);
  }
}

日期编辑区域样式

 input[type="datetime-local"] {
 /* 编辑区域整体 */
&::-webkit-datetime-edit {
  padding: 0;
  color: #fff;
}

/* 年月日时分字段 */
&::-webkit-datetime-edit-fields-wrapper {
  background: transparent;
  padding: 0 2px;
}

/* 分隔符样式 */
&::-webkit-datetime-edit-text {
  color: #7bcfd9;
  padding: 0 1px;
}

/* 单个字段悬停效果 */
&::-webkit-datetime-edit-year-field:hover,
&::-webkit-datetime-edit-month-field:hover {
  background: rgba(122, 208, 229, 0.1);
}
 }

日历图标自定义

&::-webkit-calendar-picker-indicator {
  background-image: url('your-icon.svg');
  background-size: 18px;
  background-position: center;
  width: 24px;
  height: 24px;
  cursor: pointer;
  filter: brightness(0) invert(1);
  transition: filter 0.2s;
}

&::-webkit-calendar-picker-indicator:hover {
  filter: invert(65%) sepia(60%) saturate(400%) hue-rotate(160deg);
}

下拉面板样式

/* 下拉主面板 */
&::-webkit-date-and-time-picker {
  background: #0e141c;
  border: 1px solid #7ad0e5;
  border-radius: 4px;
}

/* 时间选择器数字 */
&::-webkit-datetime-edit-hour-field,
&::-webkit-datetime-edit-minute-field {
  color: #7ad0e5;
}

/* 选中状态 */
&::-webkit-datetime-edit-year-field:focus,
&::-webkit-datetime-edit-month-field:focus {
  background: rgba(122, 208, 229, 0.2);
}

跨浏览器兼容方案

/* Firefox */
input[type="datetime-local"]::-moz-date-and-time-wrapper {
  background: transparent;
  color: #fff;
}

/* Edge */
@supports (-ms-ime-align: auto) {
  input[type="datetime-local"] {
    padding-right: 0;
  }
}
<template> <view class="form"> <uni-forms-item label="入学时间" required :label-width="100"> <uni-data-select v-model="value" :localdata="range" @change="change "></uni-data-select> </uni-forms-item> <uv-line></uv-line> <uni-forms-item label="毕业时间" required :label-width="100"> <uni-datetime-picker type="datetime" return-type="timestamp" v-model="baseFormData.datetimesingle" /> </uni-forms-item> <uv-line></uv-line> <uni-forms-item label="学历" required :label-width="100"> <uni-data-select v-model="value" :localdata="range" @change="change "></uni-data-select> </uni-forms-item> <uv-line></uv-line> <uni-forms-item label="学院" required :label-width="100"> <uni-easyinput :inputBorder="false" :clearable="false" v-model="baseFormData.name" placeholder="请填写" /> </uni-forms-item> <uv-line></uv-line> <uni-forms-item label="专业" required :label-width="100"> <uni-easyinput :inputBorder="false" :clearable="false" v-model="baseFormData.name" placeholder="请填写" /> </uni-forms-item> <uv-line></uv-line> <uni-forms-item label="考试形式" required :label-width="100"> <uni-data-select v-model="value" :localdata="range" @change="change "></uni-data-select> </uni-forms-item> <uv-line></uv-line> <uni-forms-item label="学习形式" required :label-width="100"> <uni-data-select v-model="value" :localdata="range" @change="change "></uni-data-select> </uni-forms-item> <uv-line></uv-line> </view> </template> <script> export default { data() { return { baseFormData: { name: &#39;&#39;, age: &#39;&#39;, single: "2021-04-3", introduction: &#39;&#39;, datetimesingle: 1627529992399, }, value: 0, range: [{ value: 1, text: "硕士" }, { value: 2, text: "本科" }, { value: 3, text: "大专" }, ], } }, mounted() { setTimeout(() => { this.single = "2021-5-1"; }, 1000); }, methods: { } } </script> <style> .content { display: flex; flex-direction: column; align-items: center; justify-content: center; } .text-area { display: flex; justify-content: center; } .title { font-size: 36rpx; color: #8f8f94; } </style> 我想在毕业时间那里添加有个请选择的按钮和向右箭头,点击即选择时间
最新发布
03-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

前端熊猫

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

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

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

打赏作者

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

抵扣说明:

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

余额充值