Remove all styling and functionality from <input type=“date” /> besides keyboard

冷暖自知 提交于 2019-12-25 11:54:16

问题


I've been having a lot of issues figuring out how to get rid of all browser functionality associated with <input type="date" /> but keeping it as that type in order to trigger appropriate software keyboards on mobile.

So far:

::-webkit-datetime-edit-fields-wrapper { display: none !important; }
  ::-webkit-datetime-edit-text { display: none !important; }
  ::-webkit-datetime-edit-month-field { display: none !important; }
  ::-webkit-datetime-edit-day-field { display: none !important; }
  ::-webkit-datetime-edit-year-field { display: none !important; }
  ::-webkit-inner-spin-button { display: none !important; }
  ::-webkit-calendar-picker-indicator { display: none !important; }

These seem to be all values associated to this input type, but adding display none of them basically renders input unusable, i.e. no text or placeholders are visible.


回答1:


how to get rid of all browser functionality associated with <input type="date" />

readonly attribute

Any form element can take a readonly attribute.

Example:

<input type="date" readonly />

disabled attribute

Any form element can take a disabled attribute.

Example:

<input type="date" disabled />

pointer-events: none;

For what it's worth you can also style your <input /> with the following CSS:

pointer-events: none;

Example:

input['type="date"'] {
pointer-events: none;
}
<input type="date" />


来源:https://stackoverflow.com/questions/43586664/remove-all-styling-and-functionality-from-input-type-date-besides-keyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!