What is the best way to replace the file browse button in html?

前端 未结 5 1980
闹比i
闹比i 2020-12-03 07:59

I know that it\'s possible to replace the browse button, which is generated in html, when you use input tag with type=\"file.

I\'m not sure

5条回答
  •  借酒劲吻你
    2020-12-03 08:07

    The best way is to make the file input control almost invisible (by giving it a very low opacity - do not do "visibility: hidden" or "display: none") and absolutely position something under it - with a lower z-index.

    This way, the actual control will not be visible, and whatever you put under it will show through. But since the control is positioned above that button, it will still capture the click events (this is why you want to use opacity, not visibility or display - browsers make the element unclickable if you use those to hide it).

    This article goes in-depth on the technique.

提交回复
热议问题