Reputation: 1961
I have a question regarding the styling of the input type file button. Since I cannot style the file input button, can I make a div that I can style how I want and when I click it , it triggers the input type button which opens the browse window ? If yes, any suggestions how to do it ? Thank you.
Upvotes: 2
Views: 6957
Reputation: 118
You can style the file input with just css
label[for="file-input"] {
display: block;
margin-bottom: 1em;
font-size: 1em;
color: #fff;
opacity: .9;
font-weight: bold;
}
input[type="file"] {
cursor: pointer !Important;
}
input[type="file"]::-webkit-file-upload-button {
border: none;
padding: 5px 12px;
background: #9e2baf;
color: #fff;
font-size: 1em;
transition: all .4s;
cursor: pointer;
border-radius: 20px;
}
input[type="file"]::-ms-browse {
border: none;
padding: 5px 12px;
background: #9e2baf;
color: #fff;
font-size: 1em;
transition: all .4s;
cursor: pointer;
border-radius: 20px;
}
<label class="file-label" for="input-file">Attach file:</label>
<br /> <input type="file" name="attachment[]" multiple="multiple">
Upvotes: 4
Reputation: 12683
May be you can hide the input element and make use of a div for styling purposes..
<input type="file" id="myFileInput" onchange="$('#myFileDiv').text($(this).val());" style="display:none;" />
<div id="myFileDiv" onclick="$('#myFileInput').click();">
Select File..
</div>
Upvotes: 4
Reputation: 9489
Yes you can, this is one of the most used hacks for styling file-input.
Take a look at http://www.quirksmode.org/dom/inputfile.html
Upvotes: 3