Every browser has some guidelines regarding how the controls should look based on the platform where they are executed.
You can not make a input file
look like in all browsers, just as you can not make a select
look the same. This happens because they have a different rendering engine; if you have two browsers with the same engine you will see that there are no differences in how they render the components. In addition, each browser adds a "default style" to the controls.
Solution
In browsers based on Webkit and IE we have the CSS property webkit-appearance
available. There is a long list of possible values (you can see them here ) but to eliminate the appearance that the Default browser uses the value none
:
input[type="file"] {
webkit-appearance: none;
}
However, in several scenarios we do not obtain the desired result. In these cases, what you need to do is a custom control .
function putFilename(filename, node) {
node.textContent = filename;
}
@import url('https://fonts.googleapis.com/css?family=Noto+Sans:400,700');
body {
padding: 20px;
text-align: center;
}
input[type="file"] {
display: none;
}
input[type="file"] + label {
background-color: #eee;
border: 2px solid #ccc;
/border-radius: 3px;
color: #555;
cursor: pointer;
font-family: 'Noto Sans';
font-size: 14px;
padding: 6px 12px;
}
input[type="file"] + label + p {
color: #555;
display: inline-block;
font-family: 'Noto Sans';
font-size: 14px;
padding: 5px 0;
}
<div class="input-file">
<input type="file" id="file" onchange="putFilename(this.files[0].name, filename)">
<label for="file">Seleccionar</label>
<p id="filename">No se ha escogido ningún archivo</p>
</div>
This way you keep a single view regardless of the browser, which is good for a better UX.