Css 有办法改变吗;浏览「;在文件上传按钮中?

Css 有办法改变吗;浏览「;在文件上传按钮中?,css,button,upload,Css,Button,Upload,我不想完全重新设计文件上传按钮的样式,我只想更改按钮上的内容。有办法做到这一点吗 是的,您可以使用“标签”标记和伪选择器进行自定义 另外:使用javascript显示文件名 基础是: /*Hide the current input file*/ input[type="file"] { display: none; } /*Show the label as custom button*/ input[type="file"]+label[for] { background-colo

我不想完全重新设计文件上传按钮的样式,我只想更改按钮上的内容。有办法做到这一点吗

是的,您可以使用“标签”标记和伪选择器进行自定义

另外:使用javascript显示文件名

基础是:

/*Hide the current input file*/
input[type="file"] {
  display: none;
}
/*Show the label as custom button*/
input[type="file"]+label[for] {
  background-color: #0af;
  color: #fff;
  padding: 4px;
}
/*Prepare pseudoelement to display file selected (when input change set the title to label with js)*/
input[type="file"]+label[for]:after {
  content: attr(title);
  padding: 4px;
}
这里是完整的代码片段:

/*Hide the current input file*/
input[type="file"] {
  display: none;
}
/*Show the label as custom button*/
input[type="file"]+label[for] {
  background-color: #0af;
  color: #fff;
  padding: 4px;
}
/*Prepare pseudoelement to display file selected (when input change set the title to label with js)*/
input[type="file"]+label[for]:after {
  content: attr(title);
  padding: 4px;
}
函数filechange(){
var f=(this.files[0]| | this.value);
document.getElementById('labelfor'+this.id.).title=
(f.name | | f.fileName | | f.replace('C:\\fakepath\\','');
}
正文{
字体系列:arial;
}
.field输入[类型=文件]{
显示:无;
}
.field输入[type=file]+标签[for]{
字体大小:12px;
}
.field输入[type=file]+标签[for]:之前{
内容:attr(标签);
边框:实心1px#0af;
填充:3x10px;
边界半径:3px;
背景色:#def;
颜色:#555;
光标:指针;
盒影:无;
右边距:2px;
}
.field输入[type=file]+标签[for]:悬停:在{
盒影:0px 0px 1px rgba(0,0,0,0.4);
颜色:#dfdfdf;
背景色:#0af;
}
.field输入[类型=文件]+标签[用于]:活动:之前{
盒子阴影:0px 0px 6px rgba(0,0,0,0.4);
颜色:#fff;
}
.field输入[类型=文件]+标签[用于]:之后{
填充:3x10px;
内容:attr(title);
}

您能使用javascript吗?