[英]How to change the appearance of input type="date" datepicker?
我想将 input type="date" 日期选择器的默认外观从箭头更改为日历图标,并使其始终可见。
谷歌搜索这个问题发现的很少。 我在 2012 年看到下面的帖子,上面说这是不可能的,情况有变化吗?
https://developers.google.com/web/updates/2012/08/Quick-FAQs-on-input-type-date-in-Google-Chrome
尝试以下代码:
HTML
<div>
<h1>PURE CSS DATE PICKER</h1>
<label for="dateofbirth">Date Of Birth</label>
<input type="date" name="dateofbirth" id="dateofbirth">
</div>
CSS
[type="date"] {
background:#fff url(https://cdn1.iconfinder.com/data/icons/cc_mono_icon_set/blacks/16x16/calendar_2.png) 97% 50% no-repeat ;
}
[type="date"]::-webkit-inner-spin-button {
display: none;
}
[type="date"]::-webkit-calendar-picker-indicator {
opacity: 0;
}
/* custom styles */
body {
padding: 4em;
background: #e5e5e5;
font: 13px/1.4 Geneva, 'Lucida Sans', 'Lucida Grande', 'Lucida Sans Unicode', Verdana, sans-serif;
}
label {
display: block;
}
input {
border: 1px solid #c4c4c4;
border-radius: 5px;
background-color: #fff;
padding: 3px 5px;
box-shadow: inset 0 3px 6px rgba(0,0,0,0.1);
width: 190px;
}
你也可以尝试引导日期选择器: Bootstrap Datepicker
基本上我会做的是将输入包装在一个相对定位的 div 中,在输入之后放置绝对位置的日历图标
HTML:
<div class="date-input-wrapper">
<input type="date" required />
<img src="your_icon.svg">
OR
<i class="some-icon-font some-icon">
</div>
CSS:
input[type=date]::-webkit-inner-spin-button {
-webkit-appearance: none;
display: none;
}
input[type=date]::-webkit-calendar-picker-indicator {
-webkit-appearance: none;
display: none;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.