在html中替换文件浏览按钮的最好方法是什么? [英] What is the best way to replace the file browse button in html?

查看:129
本文介绍了在html中替换文件浏览按钮的最好方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道当您使用type =file的输入标签时,可以替换html中生成的浏览按钮。

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 what is the best way, so if someone has experience with this please contribute.

推荐答案

最好的方法是使文件输入控制几乎不可见低不透明度 - 不执行可见性:隐藏 display:none ),并绝对定位下面的东西 - strong>。

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).

本文深入了解技术。

这篇关于在html中替换文件浏览按钮的最好方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆