Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

making a input type "file" hidden with button

I was wondering if this is doable? Google comes up with nothing.

Basically i want to my button to simulate when selected, allowing users to upload files. I've read its possible with labels, but i need to do with a button to do UX/UI

<button style="position:fixed;bottom:10px;right:70px" type="button" class="btn btn-default">     <input type="file" id="files" visbility="hidden" />     <span class="glyphicon glyphicon-folder-open" aria-hidden="true"></span> </button> 

Currently my button looks like this: enter image description here to this:

enter image description here

like image 842
Apprentice Programmer Avatar asked Mar 25 '15 08:03

Apprentice Programmer


People also ask

How do you make an input type file invisible?

The <input type="hidden"> defines a hidden input field. A hidden field lets web developers include data that cannot be seen or modified by users when a form is submitted. A hidden field often stores what database record that needs to be updated when the form is submitted.

What is input file type?

<input type="reset"> <input type="search"> <input type="submit">


2 Answers

You can actually do it with label, you just have to hide the input.

<!-- head -->  <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>    <!-- body -->  <label for="upload">        <span class="glyphicon glyphicon-folder-open" aria-hidden="true"></span>        <input type="file" id="upload" style="display:none">  </label>
like image 118
qtgye Avatar answered Sep 17 '22 03:09

qtgye


try an opacity of 0

opacity:0; 

https://jsfiddle.net/m4e0y2o3/12/

plus fallbacks if you what to support older browsers

.hiddenFileInput > input{    height: 100%;    width: 100;    opacity: 0;    cursor: pointer;  }  .hiddenFileInput{    border: 1px solid #ccc;    width: 100px;    height: 100px;    display: inline-block;    overflow: hidden;    cursor: pointer;        /*for the background, optional*/    background: center center no-repeat;    background-size: 75% 75%;    background-image:  url(data:image/svg+xml;utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIj8+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiBoZWlnaHQ9IjUxMnB4IiB2ZXJzaW9uPSIxLjEiIHZpZXdCb3g9Ii01MyAxIDUxMSA1MTEuOTk5MDYiIHdpZHRoPSI1MTJweCI+CjxnIGlkPSJzdXJmYWNlMS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