Removing Default Text from HTML5 Date Input
The HTML5 input element with type="date" provides a convenient way to select dates, but it often displays a default date format (e.g., mm/dd/yyyy) as a placeholder within the input field. This placeholder text can be distracting or undesirable in certain situations.
To remove this default text while still allowing users to select dates:
Use the CSS '::-webkit-datetime-edit-*' selectors:
These selectors target specific parts of the date input element, including the year, month, and day fields.
Set the color to transparent for empty fields:
By setting the color to transparent for fields that do not have a currently selected value (i.e., fields with a blank 'aria-valuenow' attribute), you can effectively hide the default placeholder text.
::-webkit-datetime-edit-year-field:not([aria-valuenow]), ::-webkit-datetime-edit-month-field:not([aria-valuenow]), ::-webkit-datetime-edit-day-field:not([aria-valuenow]) { color: transparent; }
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3