2

I tried customizing a file upload button using css.

<label  class="custom-file-input">
   <input type="file" name="file" id="videofile" /> <!--class="dropzone"-->
</label>

Full Code in jsfiddle. https://jsfiddle.net/2e7dLvoy/

How can i show the file name that is choosen just like a normal file upload button?

enter image description here

6
  • You have the input element hidden that displays the file name. Commented Feb 4, 2016 at 6:39
  • i removed it and now the button overlapped. jsfiddle.net/2e7dLvoy/1 Commented Feb 4, 2016 at 6:44
  • Just found this link Commented Feb 4, 2016 at 6:44
  • change your css bro because confliction is come from css and the file name is hidden by css so you first simply check your file without css Commented Feb 4, 2016 at 6:44
  • The button isn't overlapped, you need to give the input more than 100px Commented Feb 4, 2016 at 6:46

2 Answers 2

2

Use this

HTML:

<div class="form-group upload_btn">

  <div class="fileUpload pull-left">
    <span>Browse</span>
    <input type="file" class="upload " id="uploadBtn">
  </div>
  <input disabled="disabled" class="input pull-left" placeholder="Upload your resume" id="uploadFile">
</div>

Css:

.form-group.upload_btn {
  overflow: hidden;
  margin-bottom: 20px;
}

.fileUpload {
  background: #e1e1e1 none repeat scroll 0 0;
  color: #626262;
  display: inline-block;
  font-size: 18px;
  font-weight: 300;
  overflow: hidden;
  padding: 5.5px 10px;
  position: relative;
}

.pull-left {
  float: left;
}

.fileUpload input.upload {
  cursor: pointer;
  font-size: 20px;
  left: 0;
  margin: 0;
  opacity: 0;
  padding: 0;
  position: absolute;
  top: 0;
}

.upload_btn .input {
  width: 79%;
}

.input {
  border: 0px;
  padding: 8px;
  box-shadow: none;
  background-color: #fff;
}

Js:

document.getElementById("uploadBtn").onchange = function () {
    document.getElementById("uploadFile").value = this.value;
};

Here is the jsfiddle link

Sign up to request clarification or add additional context in comments.

1 Comment

HI. This is not working in chrome version 50? previously i was using your code and the css work on version 49.. now that i update my chrome to version 50 the layout does not work.. Not sure why it work on jsfiddle but not when i download the code and test in chrome v50. i.imgur.com/J6mz0hr.jpg
1

try this:

fiddle with jquery: https://jsfiddle.net/2e7dLvoy/4/

HTML

 <label  class="custom-file-input">
   <input type="file" name="file" id="videofile" /> <!--class="dropzone"-->
   <p id="selectedFile"></p>
 </label>

CSS

.custom-file-input {
    display: inline-block;
    position: relative;
    color: #533e00;
}
.custom-file-input input {
    visibility: hidden;
    width: 100px
}
.custom-file-input:before {
    content: 'Drag & Drop';
    display: block;
    background: -webkit-linear-gradient( -180deg, #ffdc73, #febf01);
    background: -o-linear-gradient( -180deg, #ffdc73, #febf01);
    background: -moz-linear-gradient( -180deg, #ffdc73, #febf01);
    background: linear-gradient( -180deg, #ffdc73, #febf01);
    border: 3px solid #dca602;
    border-radius: 10px;
    padding: 5px 0px;
    outline: none;
    white-space: nowrap;
    cursor: pointer;
    text-shadow: 1px 1px rgba(255,255,255,0.7);
    font-weight: bold;
    text-align: center;
    font-size: 10pt;
    position: absolute;
    left: 0;
    font-size: 12px;
}
.custom-file-input:hover:before {
    border-color: #febf01;
}
.custom-file-input:active:before {
    background: #febf01;
}
p {
    float: left;
    margin: -5% 14% 0% 32%;
}

jQuery

$('input[type=file]').change(function(e){
            $in=$(this);
            $('#selectedFile').html($in.val());
});

1 Comment

Thanks..If my answer was helpful then accept it by clicking right marker and give up vote. This is the best way to appreciate the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.