HTML File upload field style

こ雲淡風輕ζ 提交于 2019-12-01 18:12:59

If what you mean is the text field for the file names, you can use the input[type=file] selector in the css files. For example :

input[type=file] { background-color: red; }

If what you mean is the file selection dialog box, I think it's browser/OS dependent and there's little (if any) you can do about it.

I have come up on this problem before. Unfortunately, file uploads are nearly impossible to style consistently across browsers. As of CSS 2, I think, the W3C standard specifically leaves behavior undefined--think of how many ways it would need to be implemented on different platforms. Firefox, for example, generates anonymous button and input elements inside the file upload element which only inherit some of the properties that you set on the upload element itself.

You can get some to work using, for example, Furuno's method, but know that the behavior will be spotty and differ widely across platforms/browsers.

This would fit for your requirement.

If you are using jQuery, have a look at this plugin - https://github.com/ajaxray/bootstrap-file-field

This tiny plugin will display the file input field as a bootstrap button (with configurable classes) and will show selected file names (or selection errors) beautifully.

Additionally you can set various restrictions using simple data-attributes or JS settings.
e,g, data-file-types="image/jpeg,image/png" will restrict selecting file types except jpg and png images.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!