JSFiddle - React, Tailwind, and code Playground
HTML
<div class="myLabel">
<input type="file"/>
<span>My Label</span>
</div>
<br/>
Looks good, but now see what the clickable areas really are:
<br/>
<div class="myLabel">
<input type="file" style="opacity:1;"/>
<span>My Label</span>
</div>
!!
<br/>
Try clicking the !! there, using Chrome.
CSS
.myLabel {
position: relative;
}
.myLabel input {
position: absolute;
z-index: 2;
opacity: 0;
width:100%;
height:100%;
}
/* Example custom styling */
.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;
}