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 ...
随机推荐
- html 自定义上传图片样式,并回显
<div id="photoUpLoad"> <input type="file" id="photo" name=&qu ...
- ES6学习笔记(数组)
1.扩展运算符:, 2, 3]) // 1 2 3 console.log(1, ...[2, 3, 4], 5) // 1 2 3 4 5 用于函数调用 function add(x, y) { r ...
- NetCore+MySql+EF 数据库生成实体模型
NetCore版本 2.1 1.点击“工具”->“NuGet包管理器”->“程序包管理器控制台” 分别安装以下几个包 Mysql 版本: MySql.Data.EntityFrame ...
- 从零开始学spring cloud(四) -------- 基础项目搭建
1.创建一个spring cloud项目 1.1.使用工具创建--idea 点击creat new project,选择spring initializr 点击next,选择下一步 填入自己的Grou ...
- jsp4
SESSION ID=B564A2D318ECDF70EB94C6DE2080E951 SESSION ID=B564A2D318ECDF70EB94C6DE2080E951 SESSION ID=B ...
- 监控服务器配置(二)-----Grafana安装配置
1.下载grafana安装包(linux版)到 /opt/minitor/grafana . 下载地址:https://download.csdn.net/download/a15565772151/ ...
- idea配置git,查看git代码&拉取git项目至本地
1.点击file,右键选择setting 选择本地git安装路径 Ps:从git上导入一个全新的maven项目 点击clone按钮后,会弹出如下截图弹窗,点击 NO 项目已经拉取到本地,然后点击ope ...
- 通过PHP调用微信JSSDK实例
JSSDK使用步骤: 1. 先登录微信公众平台进入“公众号设置”的“功能设置”里填写“JS接口安全域名”. 2. 采用http GET方式请求获得access_token(有效期7200秒). 3. ...
- docker-3 Apache
docker 安装 Apache 环境 docker pull httpd 文件创建连接(这样就可以不用发布了,两个文件夹会自动同步文件) ln -s /root/jenkins_home/works ...
- Python学习——1
我是一名刚入IT行业的小白,目前主要是做网络运维这一块.曾经总是认为我是做网络运维的,学习代码干啥啊?后来就慢慢发现,传统的运维方式让我的效率好像不如别人效率高,关键还TM看别人比我更轻松.每一个网络 ...