Styling an input type=file button
Styling file inputs are notoriously difficult, as most browsers will not change the appearance from either CSS or javascript.
Even the size of the input will not respond to the likes of:
<input type="file" style="width:200px">
Instead, you will need to use the size attribute:
<input type="file" size="60" />
For any styling more sophisticated than that (e.g. changing the look of the browse button) you will need to look at the tricksy approach of overlaying a styled button and input box on top of the native file input. The article already mentioned by rm at www.quirksmode.org/dom/inputfile.html is the best one I've seen.
UPDATE
Although it's difficult to style an <input>
tag directly, this is easily possible with the help of a <label>
tag. See answer below from @JoshCrozier: https://stackoverflow.com/a/25825731/10128619
Styling of the input type file not working
We cannot do much customization of the file input. But you have options like below.
Note: I have used Bootstrap for some classes as your code is using it. But if you want you can have custom classes as well.
One disadvantage is that the select file information is also hidden. If you want that you can get that using JavaScript and show below the button.
input[type='file'] {
width: 0;
height: 0;
overflow: hidden;
opacity: 0;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<label>
<input id="Image" type="file" class="form-control-image" name="image_reference">
<span class="btn btn-primary">File button</span>
</label>
<br />
<br />
<button class="btn btn-primary form-control-image">Submit</button>
How to style a “choose file” button using CSS only
File type is a native element henceforth you cant change it's appearance. Instead you can hide at the back of some element.
<div>
Choose File
<input type="file" class="hide_file">
</div>
div{
padding:5px 10px;
background:#00ad2d;
border:1px solid #00ad2d;
position:relative;
color:#fff;
border-radius:2px;
text-align:center;
float:left;
cursor:pointer
}
.hide_file {
position: absolute;
z-index: 1000;
opacity: 0;
cursor: pointer;
right: 0;
top: 0;
height: 100%;
font-size: 24px;
width: 100%;
}
Refer Here
Hide choose file button of input[type='file'] without hiding file choosen name with simple css
Here you can easily remove choose file button of input type file without losing filename label with just simple CSS.
input[type=file]::-webkit-file-upload-button {
visibility: hidden;
}
How to customize input type=file?
You can’t modify much about the input[type=file]
control itself.
Since clicking a label
element correctly paired with an input will activate/focus it, we can use a label
to trigger the OS browse dialog.
Here is how you can do it…
label { cursor: pointer; /* Style as you please, it will become the visible UI component. */}
#upload-photo { opacity: 0; position: absolute; z-index: -1;}
<label for="upload-photo">Browse...</label><input type="file" name="photo" id="upload-photo" />
Styling the input type file with CSS and a little JS, is this ok?
This functionality is not available in the browsers due to security reasons.
Checkout this explanation: https://stackoverflow.com/a/15201258/586051
Only Firefox browser allows it. Refer the following example in Firefox.
EDIT: You can get the file name of the selected file this way:
EDIT2: The following code snippet demonstrates the styling of file upload button. Here we are actually faking it but the end user wouldnt know about it. ;)
EDIT3: Added value of fullPath
in the comment.
EDIT4: Added <div>
wrapper in HTML
document.getElementById("customButton").addEventListener("click", function(){ document.getElementById("fileUpload").click(); // trigger the click of actual file upload button});
document.getElementById("fileUpload").addEventListener("change", function(){ var fullPath = this.value; // fetched value = C:\fakepath\fileName.extension var fileName = fullPath.split(/(\\|\/)/g).pop(); // fetch the file name document.getElementById("fileName").innerHTML = fileName; // display the file name}, false);
#fileUpload{ display: none; /* do not display the actual file upload button */}
#customButton{ /* style the fake upload button */ background: yellow; border: 1px solid red;}
<div> <input type="file" id="fileUpload"> <!-- actual file upload button --> <button id="customButton">My Custom Button</button> <!-- fake file upload button which can be used for styling ;) --> <span id="fileName"></span></div>
How to change the color of the Choose File button (wordpress)?
You can make use of ::file-selector-button
since the upload button is part of the pseudo-element.
.hide-if-value input[type=file]::file-selector-button {
color: red;
}
<div class="hide-if-value">
<label class="acf-basic-uploader">
<input type="file" name="acf[field_60bc599999c5]" id="acf-field_60bc599999c5">
</label>
</div>
React js customizing the input of type file using CSS
You can achieve this with label and hiding the input.You need to of course style it properly and write a handleFile function.
<div>
<label onChange={handleFile} htmlFor="formId">
<input name="" type="file" id="formId" hidden />
<Icon>
</label>
</div>
How to customize the input type file button and text box
After watching your image, i think u want input type as a textbox and not button.Can u try with keeping input type file as hidden and have textbox like this
<input id="txt" type = "text" value = "Choose File"
onclick ="javascript:document.getElementById('file').click();">
<input id = "file" type="file" style='visibility: hidden;' name="img" onchange="ChangeText(this, 'txt');"/>
function ChangeText(oFileInput, sTargetID) {
document.getElementById(sTargetID).value = oFileInput.value;
}
You can easily apply css to this textbox
DEMO
Changing style of file browse button
No, it cannot be changed.
However there is a trick widely circulated around the web. The idea is to give the <input type="file"/>
an opacity value of 0.1
and position it on top of an image. For all practical purposes it will be invisible and only the picture will be visible, but it will receive mouse clicks. With some Javascript then you can show the selected file name(s) elsewhere on the page.
Related Topics
How to Align Anchor Tag With Button in Center
How to Properly Escape Quotes Inside HTML Attributes
Provide an Image for Whatsapp Link Sharing
How to Disable a Checkbox Based on Conditions in Angular 6
Preventing Overlap of Multiple Fixed Positioned Elements
Parent Div Don't Wrap Child Div
How to Hide an HTML Table Row <Tr> So That It Takes Up No Space
How to Remove Specific Text With CSS
Browsers Try to Download HTML File Instead of Opening
Limit Number of Digits After Decimals in Text Input
Using HTML Anchor Link #Id in Angular 6
Chrome User Agent Stylesheet Overwriting My Site Style
How to Force Div Contents to Stay in One Line With HTML and CSS
Disable Certain Dates from Html5 Datepicker
Reverse Order of Columns in CSS Grid Layout
Html Text Input Field With Currency Symbol
What to Do Regular Expression Pattern Doesn't Match Anywhere in String