Just want to the style of:
<input type="file" value="Choose the file" />
looks like:
<a href="#">Choose the file</a>
just using css.
Is it possible?
You can set the value of the input tag to some kind of a link, but it would not work as a hyperlink. The only way for the user to access that URL is to copy it and then paste it to the URL bar. What you should do is to put an <a> tag after this input tag, which is what the most sites are doing.
A style attribute on an <input> tag assigns a unique style to the input control. Its value is CSS that defines the appearance of the input element.
How about using label
instead of anchor
and you connect the label
with input[type="file"]
via for
:
label{
color: blue;
cursor: pointer;
}
label:hover{
text-decoration: underline;
}
#file_input_id{
display:none;
}
<label for="file_input_id">I'm a wannabe link</label>
<input type="file" id="file_input_id">
Note: safari has issues with using display:none
to input[type="file"]
It will likely require some fine tuning for the size, hover state etc, but why not do:
span {
cursor: pointer;
}
a {
position: relative;
overflow: hidden;
}
span:hover a {
color: red;
}
a + input {
position: absolute;
top: 0;
left: 0;
opacity: 0;
}
<span><a href='#'>Link!</a><input type='file' /></span>
The basic premise is that the input type=file
should be absolutely positioned over the link with its opacity set to zero so it still traps the normal user interaction behaviour.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With