Saying I have an input type="file"
field. One can drop a file on this input
(like in Firefox) instead of clicking "browse" and selecting the file.
Now, I want to customize it a bit, by changing the field's background color when one is about to drop a file in the input
. I cannot really use :hover
since it matches even when you're not drag&dropping. Is there a CSS (pseudo-class) to do that?
And is there a CSS way to style different if the file being dropped is not accepted and if it is? Say, if the field accepts only PNG files using accept
attributes, I would make the field green if you're about to drop a PNG file on it, and red if that's another type of file.
Is there a CSS way to do these today? Is there a planned way to do so in CSS (like in upcoming specs/in current specs but not implements anywhere)?
UPDATE: Thanks to @Renato's comment, according to https://github.com/w3c/csswg-drafts/issues/2257, the drop pseudo-class has been dropped now.
There is :drop
and :drop()
pseudo-class, which is currently in Working Draft status.
According to http://css4.rocks/selectors-level-4/drag-and-drop-pseudo-class.php, the browser support is not good.
For "file being dropped is not accepted" case, :drop(invalid active)
is expected to work, in future.