[ACCEPTED]-Custom Upload Button-upload

Accepted answer
Score: 34

Although some of these answers will create 9 something that looks like you want it to 8 work, they will break down when they try 7 to perform the way that you expect. The 6 file input doesn't style well directly and 5 you will have trouble trying it. However, there 4 is a trick.

The trick is to turn the opacity 3 of the input to 0 and then change the background 2 underneath it to the button style that you 1 want.

.file_button_container,
.file_button_container input {
     height: 47px;
     width: 263px;
 }

 .file_button_container {
     background: transparent url(http://i.stack.imgur.com/BT5AB.png) left top no-repeat;
 }

 .file_button_container input {
     opacity: 0;
 }
<div class="file_button_container"><input type="file" /></div>
Score: 24

I think you can also try doing it this way:
Creating 2 an additional <label for="X"></label> element which you can style 1 easily with CSS

<div class="container">
  <label for="upload" class="uploadButton">Upload</label>
  <input type="file" name="upload" id="upload">
</div>

like

.container {
  position: relative;
}
.uploadButton {
  height: 25px;
  width: 66px;
  display: block;
  cursor: pointer;
  background: url('http://www.ifunia.com/images/christmas/youtube-upload-button.gif') center center no-repeat;
}
input[type="file"] {
  display: block;
  width: 66px;
  height: 25px;
  clip: rect(0px 0px 0px 0px);
  position: absolute;
  left: 0;
  top: 0;
}
<form>
  <div class="container">
    <label for="upload" class="uploadButton"></label>
    <input type="file" name="upload" id="upload" required />
  </div>
  <hr/>
  <button type="submit">Submit</button>
</form>
Score: 1

The arrow isn't something you can "just 4 do with code" and the rounded corners would 3 work fine in firefox, but not in ie using 2 css... if you just need to use a custom 1 image it's easy:

css:

#my_upload_button{
  background-image:url(path-to-file.png);
  border:none;
}
Score: 1

In Vue JS If you wanna put the upload image 8 button inside the textarea use Relative 7 and Absolute position to put the camera 6 icon inside the textarea use bottom-3 right-4 5 to find the proper position

<div class="field relative">
        <label>Description</label>
        <textarea class="textarea" v-model="description" type="text" maxlength="10000"> </textarea>
        <label for="upload-file" class="icn icn-camera cursor-pointer absolute bottom-3 right-4">
          <input type="file" id="upload-file" hidden ref="file" @change="getImage($event)" accept="image/**" />
        </label>
  </div>

if not inside 4 the textarea box, just one custom upload 3 button then just keep the code like this

 <label for="upload-file" class="icn icn-camera cursor-pointer">
      <input type="file" id="upload-file" hidden ref="file" @change="getImage($event)" accept="image/**" />
    </label>

change 2 the default upload file icon to a camera 1 icon

Score: 0

Use CSS to style the button by its id or 1 class.

This might help: http://speckyboy.com/2009/05/27/22-css-button-styling-tutorials-and-techniques/

Score: 0

Step 1. Create a simple html markup

<div class="fileUpload btn btn-primary">
    <span>Upload</span>
    <input type="file" class="upload" />
</div>

Step 1 2. CSS: Tricky Part

.fileUpload {
    position: relative;
    overflow: hidden;
    margin: 10px;
}
.fileUpload input.upload {
    position: absolute;
    top: 0;
    right: 0;
    margin: 0;
    padding: 0;
    font-size: 20px;
    cursor: pointer;
    opacity: 0;
    filter: alpha(opacity=0);
}

For demo see here http://geniuscarrier.com/how-to-style-a-html-file-upload-button-in-pure-css/

Score: 0

Use the input's label as custom upload button:

<label for="pic" class="uploadfilelabel" >upload </label>
<input type="hidden" name="MAX_FILE_SIZE" value="110000">
<input id="pic" name="pic" type="file" size="110000">

and 3 CSS:

 label.uploadfilelabel{/*custom label here*/}
 input[type=file]{display:none;}

Notice that we did not display the main 2 input button, because otherwise it will 1 occupy space

Score: 0

I'm too late to answer but someone surely 4 will find this useful in future, no need 3 to use of Javascript or Hidden field too. If 2 you are using Bootstrap then definitely 1 there's no need of btn CSS as well.

#upload_file 
{
    display: none;
}

.btn-primary {
    background-color: #007bff;
    border-color: #007bff;
    color: #fff;
}

.btn {
    -moz-user-select: none;
    border: 1px solid transparent;
    border-radius: 0.25rem;
    display: inline-block;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    padding: 0.375rem 0.75rem;
    text-align: center;
    transition: color 0.15s ease-in-out 0s, background-color 0.15s ease-in-out 0s, border-color 0.15s ease-in-out 0s, box-shadow 0.15s ease-in-out 0s;
    vertical-align: middle;
    white-space: nowrap;
}
<label for="upload_file" class="custom-file-upload btn btn-primary"><i class="fa fa-cloud-upload"></i> File Upload</label>
<input class="margin" type="file" formnovalidate id="upload_file" name="file" accept="*">

More Related questions