File Upload Control CSS Style
Quick fiddle displaying how to style the file upload control with custom text and picture.
by Erin
HTML
<h1>File Upload Control</h1>
<span class="versus">with CSS...</span>
<div id="photoWrapper">
<label>
<input type="file"></input>
<div class="newInputWrapper">
<!-- custom picture -->
<span id="photo"></span>
<!-- custom text -->
<p class="filename">Add Picture</p>
</div>
</label>
</div>
<span class="versus">without CSS...</span>
<input type="file"></input>
CSS
.versus {
font-weight: bold;
display: block;
margin: 1em auto;
}
#photoWrapper label {
display: table-cell;
vertical-align: middle;
padding: 0;
margin: 0;
}
#photoWrapper .newInputWrapper {
display: table;
}
#photoWrapper .newInputWrapper p {
font-size: 1em;
color: #959391;
padding-left: 0.5em;
display: table-cell;
vertical-align: middle;
}
#photoWrapper label > input[type=file] {
visibility: hidden;
position: absolute;
}
#photoWrapper label > input + .newInputWrapper span {
cursor: pointer;
height: 29px;
width: 28px;
display: table-cell;
vertical-align: middle;
-webkit-user-select: none;
-moz-user-select: none;
-khtml-user-select: none;
-ms-user-select: none;
}
#photo {
background: url('https://erinbamberger.files.wordpress.com/2015/04/add-photo.jpg');
background-repeat: no-repeat;
background-size: 75% auto;
}
JavaScript
$(function() {
$("input:file").change(function (){
var fileName = $(this).val();
$(".filename").html(fileName);
});
});