1

I want to change the css for file_field. Instead of showing original browse button. I want to use simple upload button to upload file.

How may i change the css of file_field and set another image on it ? So it will look like a button instead of file upload control.

krunal shah
  • 16,089
  • 25
  • 97
  • 143
  • 2
    possible duplicate of [Style input type file?](http://stackoverflow.com/questions/4909228/style-input-type-file) – JohnP Mar 27 '11 at 11:41

1 Answers1

0

View

        <% form_tag({:controller => "controller_name", :action => "file_upload"}, {:multipart => true}) do%>
          <div class="fileinputs">
            <input type="file" name="upload" id="upload" class="file" onchange="this.form.submit();" />
            <div class="fakefile">
              <input class="upload_btn"/>
            </div>
          </div>
        <% end %>

CSS

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;
}

input.upload_btn {
    background:transparent url(/images/upload_btn.gif) no-repeat scroll 0px 0px ;
    width:79px;
    height:26px;
    cursor:pointer;
    border:0px;
}

input.upload_btn:hover {
    background:transparent url(/images/upload_btn.gif) no-repeat scroll 0px -40px ;
}
krunal shah
  • 16,089
  • 25
  • 97
  • 143