Home >Web Front-end >CSS Tutorial >How Can I Style File Upload Buttons Without JavaScript?
Many attempts to customize file upload buttons often resort to JavaScript or Quirksmode's approach, which has limitations in terms of dimensions and automatic adjustments. This article explores a less hacky solution using the
The
<label class="myLabel"> <input type="file" required/> <span>My Label</span> </label>
label.myLabel input[type="file"] { position:absolute; top: -1000px; } .myLabel { border: 2px solid #AAA; border-radius: 4px; padding: 2px 5px; margin: 2px; background: #DDD; display: inline-block; } .myLabel:hover { background: #CCC; } .myLabel:active { background: #CCF; } .myLabel :invalid + span { color: #A44; } .myLabel :valid + span { color: #4A4; }
In this example, we hide the file upload button using position:absolute and top:-1000px and style the
The above is the detailed content of How Can I Style File Upload Buttons Without JavaScript?. For more information, please follow other related articles on the PHP Chinese website!