Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change file_field_tag appearance to button appearance

I am working on a Rails project and I want to use file_field_tag but I'd like it looks like a button.

I have this:

enter image description here

with this code:

= file_field_tag 'attachment'

I want something like this:

enter image description here

and I attempted this:

= file_field_tag 'attachment', class: 'btn btn-large btn-warning'

but I got this:

enter image description here

How can I change the file_field_tag's appearance in order to achieve it looks like a button?

like image 269
Iván Cortés Romero Avatar asked Mar 16 '23 03:03

Iván Cortés Romero


1 Answers

HTML:

<span class="btn btn-large btn-warning btn-file">
    Choose File
    <%= file_field_tag :attachment %>
</span>

CSS:

.btn-file {
    position: relative;
    overflow: hidden;
}

.btn-file input[type=file] {
    position: absolute;
    top: 0;
    right: 0;
    min-width: 100%;
    min-height: 100%;
    font-size: 100px;
    text-align: right;
    filter: alpha(opacity=0);
    opacity: 0;
    outline: none;
    background: white;
    cursor: inherit;
    display: block;
}
like image 52
kjmagic13 Avatar answered Mar 26 '23 01:03

kjmagic13