input type='file'文件上传自定义样式
使用场景:
在未使用UI库时免不了会用到各种上传文件,那么默认的上传文件样式无法达到项目的要求,因此重写(修改)上传文件样式是必然的,下面的效果是最近项目中自己写的一个效果,写出来做个记录方便以后使用;
默认效果及选择文件后效果:

修改后的效果:

以下是相应的代码:
<!doctype html>
<html>
<head>
<title></title>
</head>
<style type="text/css">
.file{
margin-top: 20px;
margin-left: 20px;
}
.block {
margin-bottom: 30px;
margin-top: 20px;
height: 30px;
line-height: 30px;
} .block span {
display: inline-block;
width: 100px;
text-align: right;
font-size: 14px;
float: left;
margin-right: 15px;
} .block input {
background: #363738;
height: 30px;
width: 300px;
border: #363738;
color: #ffffff;
padding-left: 15px;
} .block .block-label {
width: 220px;
height: 30px;
background: #363738;
margin: 0;
float: left;
padding-left: 15px;
color: #fff;
} /* 文件上传样式 */ .btn_addPic {
display: inline-block;
position: relative;
width: 80px;
height: 30px;
overflow: hidden;
border: 1px solid #f9c100;
background: #f9c100;
color: #000;
cursor: pointer;
text-align: center;
font-size: 14px;
} .btn_addPic:hover {
cursor: pointer;
} .filePrew {
display: block;
position: absolute;
top: 0;
left: 0;
width: 140px;
height: 39px;
font-size: 100px;
opacity: 0;
filter: alpha(opacity=0);
/* 兼容IE */
}
</style> <body>
<div class="file">
<input type="file" name="" id="">
<input type="file" name="" id="">
</div>
<div class="block">
<span>CAD图纸:</span>
<label class="block-label" for="fileupload" id="label"></label>
<a class="btn_addPic" href="javascript:void(0);" id="fileupload">
选择
<input class="filePrew" type="file" accept="images/*" id="upload" onchange="getFileSize(this.value)">
</a>
</div>
<script>
var card = document.getElementById('label');
function getFileSize(v) {
card.innerText = v;
console.log(v)
}
</script>
</body> </html>
可直接复制粘贴查看效果!
一分积累,一份收获,愿大家每天都有进步!
input type='file'文件上传自定义样式的更多相关文章
- js 实现 input type="file" 文件上传示例代码
在开发中,文件上传必不可少但是它长得又丑.浏览的字样不能换,一般会让其隐藏点其他的标签(图片等)来时实现选择文件上传功能 在开发中,文件上传必不可少,<input type="file ...
- [置顶] js 实现 <input type="file" /> 文件上传
在开发中,文件上传必不可少,<input type="file" /> 是常用的上传标签,但是它长得又丑.浏览的字样不能换,我们一般会用让,<input type ...
- <input type="file">文件上传
<input> type 类型为 file 时使得用户可以选择一个或多个元素以提交表单的方式上传到服务器上,或者通过 Javascript 的 File API 对文件进行操作 . 常用i ...
- javascript input type=file 文件上传
在JS中,input type=file 是常用的文件上传API,但感觉W3C说的不是很清楚,同时网上的资料也比较乱. 由于做微信开发,所以网页打算尽量少用第三方库或者插件,以加快网页的加载速度.因为 ...
- input type="file"文件上传到后台读取
html页面(表单采用bootStrap) js部分: //更换头像时把上传的图片post方式到控制器 <script type="text/javascript"> ...
- input type="file"文件上传时得到文件的本地路劲
<!DOCTYPE html><html><head> <meta charset="UTF-8"> <meta name=& ...
- 修改input file 文件上传的样式
Web页面中,在需要上传文件时基本都会用到<input type="file">元素,它的默认样式: chrome下: IE下: 不管是上面哪种,样式都比较简单,和很多 ...
- input type file onchange上传文件的过程中,遇到同一个文件二次上传无效的问题。
不要采用删除当前input[type=file]这个节点,然后再重新创建dom这种方案,这样是不合理的.解释如下:input[type=file]使用的是onchange去做,onchange监听的为 ...
- input[type='file']获取上传文件路径案例
最近在项目时,需要获取用户的上传文件的路径,便写了一个demo: <body> <input type="file" name="" valu ...
随机推荐
- 采用ftpServer构建嵌入式ftp服务器时设置pass功能
讲ftpserver嵌入式ftp服务器的文章很多,但是都没有介绍pass功能设置的. apach上pass部分也是针对的ftpd服务器的xml配置,关于嵌入式ftp服务器设置pass功能的部分几乎没有 ...
- CodeWarrior10 如何复制Workspace配置到另一个workspace
https://mcuoneclipse.com/2012/04/04/copy-my-workspace-settings/comment-page-1/#comment-106061
- 我们一起踩过的坑----react(antd)(一)
1.}] && ){ ){ ){ ||){ ){ );); , }; }); }, beforeUpload: (file) => { ...
- Java中的equals和hashCode方法详解
Java中的equals和hashCode方法详解 转自 https://www.cnblogs.com/crazylqy/category/655181.html 参考:http://blog.c ...
- 腾讯2019年暑期实习生招聘提前批在线笔试技术研究和数据分析方向t2(python)
小Q有一叠纸牌,一共有n张,从上往下依次编号为1~n.现在小Q要进行以下重复操作:把位于顶端的牌扔掉,把新的顶端的牌放到这叠牌的底部.小Q会一直操作到只剩下一张牌为止,小Q想知道每次扔掉的牌的编号.[ ...
- CentOS 6安装配置mongodb
安装过程 服务器下载安装包 下载: curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-4.0.6.tgz; 解压 ...
- mysql5.7.21安装要点记录
下载的是Zip解压缩版,Windows系统,因为很久没有在Windows上安装过,这次安装发现了几处和以前安装不一样的地方,特记录如下,供大家参考 MySQL配置文件位置 bin目录下的mysql_c ...
- python字符串处理内置方法一览表
python字符串处理内置方法一览表 序号 方法及描述 1 capitalize()将字符串的第一个字符转换为大写 2 center(width, fillchar) 返回一个指定的宽度 widt ...
- LAB7 REST
r需要初始化才能赋值. 不要盲目抄doGet方法,要理解题目的意思
- sql基本的增删查改语句
1.增---用于向表中插入新的行/数据 语法:insert into 表名(值1,值2,值3...) values(值1,值2,值3,...) 或者 语法:insert [into] <表名&g ...