JSFiddle - React, Tailwind, and code Playground
by TheFiddler
HTML
Big button (not hidden so you can see what's going on)
<div class="inputWrapper" style="height: 48px; width: 128px;">
<input class="fileInput" type="file" name="file1"/>
</div><br/>
Big button (file input is hidden)
<div class="inputWrapper" style="height: 56px; width: 128px;">
<input class="fileInput hidden" type="file" name="file2"/>
</div><br/>
Medium button (this one has text)
<div class="inputWrapper" style="height: 48px; width: 96px;">
Upload File
<input class="fileInput hidden" type="file" name="file3"/>
</div><br/>
Smaller button
<div class="inputWrapper" style="height: 24px; width: 24px;">
<input class="fileInput hidden" type="file" name="file4"/>
</div>
CSS
.inputWrapper {
overflow: hidden;
position: relative;
cursor: pointer;
/*Using a background color, but you can use a background image to represent a button*/
background-color: #DDF;
}
.fileInput {
cursor: pointer;
height: 100%;
position:absolute;
top: 0;
right: 0;
/*This makes the button huge so that it can be clicked on*/
font-size:50px;
}
.hidden {
/*Opacity settings for all browsers*/
opacity: 0;
-moz-opacity: 0;
filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0)
}
/*Dynamic styles*/
.inputWrapper:hover {
background-color: #FDD;
}
.inputWrapper.clicked {
background-color: #A66;
}
body {
font-family:Helvetica;
}
JavaScript
/*You can use some jQuery to simulate a button-press effect by changing the background color/image, font size/weight/color, etc..*/
$(function() {
$(".inputWrapper").mousedown(function() {
var button = $(this);
button.addClass('clicked');
setTimeout(function(){
button.removeClass('clicked');
},50);
});
});