I know that styling file input is pretty minimal, which is not a bad thing.
Is there some way of selecting file input which is empty?
The plan is to show or hide a submit button depending on whether the file input is empty.
In modern browsers you can use :placeholder-shown to target the empty input (not to be confused with ::placeholder ).
The :empty CSS pseudo-class represents any element that has no children. Children can be either element nodes or text (including whitespace). Comments, processing instructions, and CSS content do not affect whether an element is considered empty.
If you are comfortable marking the input
as required
, you could do it with just css:
input:invalid ~ .chosen {
display: none;
}
input:valid ~ .empty {
display: none;
}
<input type="file" required><br>
<span class="empty">Empty</span>
<span class="chosen">Chosen</span>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With