I was successful in customizing the file input using jQuery and CSS3.
However, there is one thing I was not able to do. I want to show the text of the file selected after the user selected the image or file at the very bottom of the text like this:
So far here's my codes. Here's the HTML:
<div class="container-avatar">
<div class="avatar-upload">
<div class="avatar-edit">
<input accept=".png, .jpg, .jpeg" id="imageUpload" type='file'> <label for="imageUpload"></label>
</div>
<div class="avatar-preview">
<div id="imagePreview" style="background-image: url('http://softorius.ro/images/about1.jpg');"></div>
</div>
</div>
Here's the CSS:
.container-avatar {
max-width: 115px;
margin: 0px auto;
}
.avatar-upload {
position: relative;
max-width: 200px;
margin: 10px auto;
}
.avatar-upload .avatar-edit {
position: absolute;
right: 12px;
z-index: 1;
top: 10px;
}
.avatar-upload .avatar-edit input {
display: none;
}
.avatar-upload .avatar-edit input+label {
display: inline-block;
width: 34px;
height: 34px;
margin-bottom: 0;
border-radius: 100%;
background: #FFFFFF;
border: 1px solid transparent;
box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.12);
cursor: pointer;
font-weight: normal;
transition: all 0.2s ease-in-out;
}
.avatar-upload .avatar-edit input+label:hover {
background: #fff;
border-color: #d6d6d6;
}
.avatar-upload .avatar-edit input+label:after {
content: "\f040";
font-family: 'FontAwesome';
color: #007BFF;
position: absolute;
top: 6px;
left: 0;
right: 0;
text-align: center;
margin: auto;
}
.avatar-upload .avatar-preview {
width: 100px;
height: 100px;
position: relative;
border-radius: 100%;
border: 6px solid #F8F8F8;
box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.1);
}
.avatar-upload .avatar-preview>div {
width: 100%;
height: 100%;
border-radius: 100%;
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}
And here's my jQuery:
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
$('#imagePreview').css('background-image', 'url('+e.target.result +')');
$('#imagePreview').hide();
$('#imagePreview').fadeIn(650);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#imageUpload").change(function() {
readURL(this);
});
All of my codes are hosted on JSFIDDLE: https://jsfiddle.net/wtvrzj91/1/

