As I dabble around with HTML and CSS, I've been experimenting with creating a custom file selection button. I came across a method on the internet that involves hiding the original button and superimposing a new one over it using the following code:
HTML:
<div class="upload">
<input type="file" class="upload" name="upload"/>
</div>
CSS:
div.upload {
width: 157px;
height: 57px;
background-color: silver;
}
div.upload input {
display: block !important;
width: 157px !important;
height: 57px !important;
opacity: 0 !important;
overflow: hidden !important;
}
While this method does work effectively, I desired to have only text instead of an image overlaying the button. So I attempted by modifying the code as follows:
<div class="upload">
Choose File
<input type="file" class="upload" name="upload"/>
</div>
However, upon testing, I found that clicking on the label "Choose File" does not activate the file selection function of the button. It seems to register clicks only below the text label.
I'm puzzled as to why this doesn't work as intended. I even experimented with the pointer-events
property but still faced issues. How can I troubleshoot this problem and make it function correctly?