0

Possible Duplicate:
Styling <input type=“file”>
Style input type file?

I`m trying to change a default input type="file" button with the button created by css. This is my html code:

<input type="file" name="name" value="" />
<a href="#" class="button">Browse</a>

...and this is my css button code:

.button {
    display:inline;
    -moz-box-shadow:inset 0px 1px 0px 0px #fff6af;
    -webkit-box-shadow:inset 0px 1px 0px 0px #fff6af;
    box-shadow:inset 0px 1px 0px 0px #fff6af;
    background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #ffec64), color-stop(1, #f3b415) );
    background:-moz-linear-gradient( center top, #ffec64 5%, #f3b415 100% );
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffec64', endColorstr='#f3b415');
    background-color:#ffec64;
    -moz-border-radius:6px;
    -webkit-border-radius:6px;
    border-radius:6px;
    border:1px solid #f3b415;
    display:inline-block;
    color:#333333;
    font-family:arial;
    font-size:15px;
    font-weight:bold;
    padding:6px 24px;
    text-decoration:none;
    text-shadow:1px 1px 0px #ffee66;
}
.button:hover {
    background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #f3b415), color-stop(1, #ffec64) );
    background:-moz-linear-gradient( center top, #f3b415 5%, #ffec64 100% );
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#f3b415', endColorstr='#ffec64');
    background-color:#f3b415;
}
.button:active {
    position:relative;
    top:1px;
}​

Also, you can check it here

Community
  • 1
  • 1
Mikerobenics
  • 215
  • 6
  • 14

4 Answers4

2

Build a Demo as per the trick given at QuirksMode. Read it for an explanation.

HTML

<div class="fileinputs">
    <input type="file" class="file" />
    <div class="fakefile">
        <a href="#" class="button">Browse</a>

    </div>
</div>

CSS

.button {
    display:inline;
    -moz-box-shadow:inset 0px 1px 0px 0px #fff6af;
    -webkit-box-shadow:inset 0px 1px 0px 0px #fff6af;
    box-shadow:inset 0px 1px 0px 0px #fff6af;
    background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #ffec64), color-stop(1, #f3b415) );
    background:-moz-linear-gradient( center top, #ffec64 5%, #f3b415 100% );
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffec64', endColorstr='#f3b415');
    background-color:#ffec64;
    -moz-border-radius:6px;
    -webkit-border-radius:6px;
    border-radius:6px;
    border:1px solid #f3b415;
    display:inline-block;
    color:#333333;
    font-family:arial;
    font-size:15px;
    font-weight:bold;
    padding:6px 24px;
    text-decoration:none;
    text-shadow:1px 1px 0px #ffee66;
}
.button:hover {
    background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #f3b415), color-stop(1, #ffec64) );
    background:-moz-linear-gradient( center top, #f3b415 5%, #ffec64 100% );
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#f3b415', endColorstr='#ffec64');
    background-color:#f3b415;
}
.button:active {
    position:relative;
    top:1px;
}


div.fileinputs {
    position: relative;
}

div.fakefile {
    position: absolute;
    top: 0px;
    left: 0px;
    z-index: 1;
}

input.file {
    position: relative;
    text-align: right;
    -moz-opacity:0 ;
    filter:alpha(opacity: 0);
    opacity: 0;
    z-index: 2;
}​
Clyde Lobo
  • 9,126
  • 7
  • 34
  • 61
0

As per my knowledge, you can't do styling to the "Browse" button. The only work around you have here is to overlay another button on this using Z-Index; which might not be a very good practice.

Praveen
  • 1,449
  • 16
  • 25
0

File inputs are rendered by the OPERATING SYSTEM, they are not part of the HTML specification.

Diodeus - James MacFarlane
  • 112,730
  • 33
  • 157
  • 176
0

You could just adjust the input to be a button, then write a jQuery function for bringing up the file:

 <input type="button" name="name" value="Browse" class="button"/>
Corey Adler
  • 15,897
  • 18
  • 66
  • 80