css - HTML文件上传 "no file selected"文字样式

标签 css frontend

我正在构建一个需要文件上传的 html 表单。虽然我的文件上传部分正常工作,但我无法获得表单上传按钮的样式和“未选择文件”文本。

我想要的标记是

enter image description here

有办法吗?

PS:请忽略绿色文字(“上传屏幕截图”)。我有那个工作。

按钮和“未选择文件”的当前行为在同一行。

HTML代码:

<div class="formField">
   <label for="fileToUpload">Upload a screen shot (optional) </label>
   <input type="file" name="fileToUpload" id="fileToUpload"/> 
</div>

最佳答案

不能单独使用 CSS 来设置文件输入的样式。您需要使用一个 jQuery 插件,该插件制作一个可以使用 CSS 设置样式的自定义文件上传按钮。

好的叫NiceFileInput .

使用:

1。包括 jQuery(如果您还没有)和 nicefileinput.min.js

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script src="/your_path/jquery.nicefileinput.min.js"></script>

here下载文件.

2。将其绑定(bind)到您想要的元素。这将它绑定(bind)到所有文件输入:

<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
}

关于css - HTML文件上传 "no file selected"文字样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27608288/

相关文章:

jquery - 悬停时更改图像但不更改图像位置

html - 悬停背景颜色未完全显示在链接上

php - 前端性能问题

javascript - 如何在非spa项目中使用vue.js?

javascript - 从对象内调用时的 knockout.js ko.applyBindings()

javascript - 如何在对象中添加项目?

css - 生成 scss 多个 css 类*

css - 如何在 Angular 中将 ngClass 与表一起使用

html - 两栏网页,DIV溢出

jquery - magicsuggest 的 CSS 问题