18

I tried to change the HTML form, input type file. Here is my code:

HTML, form id = form

<input class="upload_file" type="file" id="file" name="file" />

.CSS

I tried both:
.upload_button{
  background: url('../images/upload_btn_bg.png') no-repeat;
  width: 200px; 
  height: 40px;
}

#form input[type=file]{
  background: url('../images/upload_btn_bg.png') no-repeat;
  width: 200px; 
  height: 40px;
}

None of both of those methods works. I did see from some website, like facebook, youtube, google or twitter, they have different style. Wonder how they do it.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
learner.php
  • 197
  • 1
  • 2
  • 5

7 Answers7

13

You can't do anything with input type file (other than huge hacks). I know this sounds horrible, but the web standards still haven't come up with a solution for that.

What I would suggest though, is that you used something more flexible, such as swfUpload, which let's you change stiles, and also check for file size prior to uploading.

Some neat examples of it can be found here

Hope this helps you

Marcos Placona
  • 21,468
  • 11
  • 68
  • 93
9

Best hack ever. Input file HTML:

<input type="file" class="hide" id='inputFile' />
<a href="#" id="triggerFile" class="btn btn-primary">Browse File</a>

using jQuery:

$('#triggerFile').on('click', function(e){
        e.preventDefault()
        $("#inputFile").trigger('click')
    });
Donald Derek
  • 2,529
  • 2
  • 23
  • 17
9

For example, try this variant http://www.quirksmode.org/dom/inputfile.html

Gopher
  • 917
  • 6
  • 18
6

Why don't you just put the css to display: none and then trigger this button with another button? This can be easily done with javascript and then you can style the button yourself completely

Here's an example of how to trigger a button with another, but this is just one of many ways: One button firing another buttons click event

Community
  • 1
  • 1
user1282947
  • 83
  • 1
  • 6
1

You can change the font-Size for height or follow this url http://www.quirksmode.org/dom/inputfile.html ( which is basically what I do in my projects ).

  • Thanks! I tried line-height but that doesn't work. Looks like font-size style on the type="file" is the only way to get tall buttons. You can see the problem here http://jsfiddle.net/gabrieleromanato/mxq9R/ also the cursor looks wrong, trying to fix that next. – PJ Brunet Apr 24 '13 at 21:50
0

Actually you can!

You have to do it with the SI.Files Library.

Here is a good article about how its done in details:

Good Luck!

TLP
  • 66,756
  • 10
  • 92
  • 149
-3

Bhee, just add CSS definitions to your html input tag:

like:

<select style:"...whatYoureadBelow..."></select>

or

<input style:"...whatYoureadBelow..." />

CSS definitions:

border:none;
background-image:url('somePathToImage');
background-repeat:no-repeat;
//those things below adjust according to your background image size
width:XXpx;
height:XXpx;

Thus you'll get what you have on facebook or elsewhere ;)

Błażej Kocik
  • 1,689
  • 1
  • 17
  • 20