HTML file upload quot;no file selectedquot; text style(HTML 文件上传“未选择文件文字样式)
问题描述
我正在构建一个需要文件上传的 html 表单.当我让文件上传部分工作时,我无法获得表单上传按钮的样式和未选择文件"文本.
I am building a html form that needs file upload. While I got the file upload part working, I am unable to get the styling of form upload button and " No file selected" text.
我想要的标记是
有办法吗?
PS:请忽略绿色文字(上传屏幕截图").我有那个工作.
PS: Please ignore the green text ( "Upload a screen shot"). I have that working.
按钮的当前行为和未选择文件"在同一行.
Current behavior the button and the "no file chosen" is in the same line.
HTML 代码:
<div class="formField">
<label for="fileToUpload">Upload a screen shot (optional) </label>
<input type="file" name="fileToUpload" id="fileToUpload"/>
</div>
推荐答案
文件输入不能单独使用 CSS 设置样式.您需要使用一个 jQuery 插件来制作一个可以使用 CSS 设置样式的自定义文件上传按钮.
File inputs can't be styled with CSS alone. You'll need to use a jQuery plugin that makes a custom file upload button that can be styled with CSS.
一个很好的叫做 NiceFileInput.
使用方法:
<script src="aHR0cDovL2FqYXguZ29vZ2xlYXBpcy5jb20vYWpheC9saWJzL2pxdWVyeS8xLjcuMC9qcXVlcnkubWluLmpz"></script>
<script src="L3lvdXJfcGF0aC9qcXVlcnkubmljZWZpbGVpbnB1dC5taW4uanM="></script>
从这里下载文件.p>
2.将其绑定到您想要的元素.这会将其绑定到所有文件输入:
<script type="text/javascript">
$(document).ready(function() {
$("input[type=file]").nicefileinput();
});
</script>
3.用 CSS 自定义它
.NFI-wrapper {
// the container div
}
.NFI-button {
// the button div element
}
.NFI-filename {
// the text input element which collects and shows the value
}
这篇关于HTML 文件上传“未选择文件"文字样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:HTML 文件上传“未选择文件"文字样式


- 失败的 Canvas 360 jquery 插件 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Flexslider 箭头未正确显示 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01