As mentioned in a couple of the comments, none of these solutions seem to be working in more recent versions of Chrome and I can verify this is still the case as of v94. As Eli mentions it seems to be problematic when attempting to select the attribute of a pseudo-element.
If you don't mind using a little bit of JavaScript to set an attribute on the <input type="date" />
element then it is possible to come up with a hacky CSS selector as a workaround.
For example, I'm using JavaScript to set a data-hasvalue
attribute once the input has a value, and then using the following SCSS.
&[type="date"]:not([data-hasvalue]):not(:invalid):not(:focus) {
&::-webkit-datetime-edit-text,
&::-webkit-datetime-edit-day-field,
&::-webkit-datetime-edit-month-field,
&::-webkit-datetime-edit-year-field {
color: rgb(117, 117, 117); // Chrome's default color for input placeholder text
}
}
Be sure that the data-hasvalue
attribute is set for all date inputs, otherwise you will get placeholder style text when a value is set. Alternatively, opt in to the behaviour by doing the opposite and targeting only when a value is not set.