Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Upload Button

hi i was just wondering how you can create you own custom file upload button, because the best i can do is

enter image description here

and what i want to achieve is

enter image description here

if there is anyway of doing this i would be very thankful, and please can i have answers that explain how to do it with code and not answers with links to websites that allow you to download a button or something like that,Thank You :)

like image 878
daka Avatar asked Jun 23 '11 22:06

daka


2 Answers

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

The trick is to turn the opacity of the input to 0 and then change the background underneath it to the button style that you 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>
like image 172
natedavisolds Avatar answered Sep 29 '22 06:09

natedavisolds


I think you can also try doing it this way:
Creating an additional <label for="X"></label> element which you can style 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>
like image 20
Alexandru Bangală Avatar answered Sep 29 '22 06:09

Alexandru Bangală