原生HTML5 input type=file按钮UI自定义
原生<input type="file" name="file" />长得太丑

提升一下颜值

实现方案一、设置input[type=file]透明度为0,使用绝对定位遮罩在自定义的按钮标签层的之上.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>原生HTML5 input type=file按钮UI自定义</title>
<style>
.file_upload_box {
display: inline-block;
width: 200px;
height: 60px;
position: relative;
overflow: hidden;
}
.file_upload_box input[type=file] {
position: absolute;
left: 0;
top: 0;
width: 100%;
line-height: 60px;
opacity: 0;
cursor: pointer;
}
.file_upload_box a {
display: inline-block;
width: 100%;
line-height: 45px;
text-align: center;
font-family: "Microsoft yahei";
background-color: #f60;
color: #FFF;
font-weight: 700;
text-decoration: none;
}
</style>
</head>
<body>
<div class="file_upload_box">
<input type="file" name="file" />
<a href="#none">上传文件</a>
</div>
</body>
</html>
推荐实现方案二、利用label的for属性(for 属性规定 label 绑定到哪个表单元素)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>原生HTML5 input type=file按钮UI自定义</title>
<style>
.ui_button {
display: inline-block;
line-height: 45px;
padding: 0 70px;
color: #FFFFFF;
font-family: "微软雅黑";
font-weight: 700;
cursor: pointer;
}
.ui_button_primary {
background-color: #FF6600;
}
label.ui_button:hover {
background-color: #d46216;
}
</style>
</head>
<body>
<label class="ui_button ui_button_primary" for="xFile">上传文件</label>
<form><input type="file" id="xFile" style="position:absolute;clip:rect(0 0 0 0);"/></form>
</body>
</html>
原生HTML5 input type=file按钮UI自定义的更多相关文章
- input type= file 如何更改自定义的样式
input { @include wh(24px,22px);//sass 宽高 @include pa(0,0); //绝对定位 top:0:left:0: opacity: 0; //透明度: o ...
- <input type="file">如何实现自定义样式
利用样式覆盖来实现效果:先看下原本和改变后的样式 1 <!doctype html> 2 <html> 3 <head> 4 <title>file自定 ...
- html中,文件上传时使用的<input type="file">的样式自定义
Web页面中,在需要上传文件时基本都会用到<input type="file">元素,它的默认样式: chrome下: IE下: 不管是上面哪种,样式都比较简单,和很多 ...
- 文件上传按钮input[type="file"]按钮美化时在IE8中的bug【兼容至IE8】
首先看一下完成后的效果,鼠标移入可改变为手指的效果. 在此就不加图标了 <label class="file-upload"> <span>上传附件< ...
- 使用自定义的按钮替换默认的<input type='file'>
可以通过让默认的input type = 'file'按钮透明度变为0,并且让它刚好覆盖在自定义的按钮上,来实现此效果: 将它写成一个jQuery插件: (function($){ $.fn.brow ...
- input type="file"使用
问题: 在实际开发过程中,会遇到上传文件的一些需求.但是使用原生的<input type="file" />在使用中存在一些问题 在未上传文件时,显示"no ...
- vue项目内嵌入到app input type=file 坑(文件上传插件)
w问题描述: 我用vue-cli完成的一个移动端项目,内嵌到app当中,用原生的input type=file 来完成文件上传.在安卓下没有问题但是在苹果手机 上传第二次手机就会发生白屏 并无缘无故跳 ...
- 自定义上传按钮 <input type="file" name = "file"/> (将file隐藏在button下)
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- 自定义样式 实现文件控件input[type='file']
一般我们设计的上传按钮都是和整个页面风格相似的样式,不会使用html原生态的上传按钮,但是怎么既自定义自己的样式,又能使用file控件功能呢? 思路是这样的: 1.定义一个相对定位的DIV,按照整成步 ...
随机推荐
- 2013 duilib入门简明教程 -- 部分bug 2 (14)
上一个教程中提到了ActiveX的Bug,即如果主窗口直接用变量生成,则关闭窗口时会产生崩溃 如果用new的方式生成,则不会崩溃,所以给出一个临时的快速解决方案,即主窗口 ...
- JS数字计算精度误差的解决方法
本篇文章主要是对javascript避免数字计算精度误差的方法进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助. 如果我问你 0.1 + 0.2 等于几?你可能会送我一个白眼,0.1 + 0. ...
- DDD 领域驱动设计-在动手之前,先把你的脑袋清理干净
惨不忍睹的翻译 英文原文:http://www.codeproject.com/Articles/339725/Domain-Driven-Design-Clear-Your-Concepts-Bef ...
- Android样式之selector
日常开发当中,难免会出现这样一种情况,为一个按钮.TextView...设置一个点击状态的颜色改变,可能是background背景的改变,也可能是字体颜色的改变,简单点说:默认状态下,字体颜色或者背景 ...
- Java多线程系列--“JUC锁”02之 互斥锁ReentrantLock
本章对ReentrantLock包进行基本介绍,这一章主要对ReentrantLock进行概括性的介绍,内容包括:ReentrantLock介绍ReentrantLock函数列表ReentrantLo ...
- 项目总结---- imageLoder 的2个Bug解决方法、1.9.4如何选择性删除disk缓存和其它一些错误。
我们不说废话,直接入主题,抓紧时间写完,好继续找bug... (PS:imageLoder的bug 百度不到的哦,不过我坚信我的观点没错) 版本1.9.2,1.9.4我没测试 1,imageLoder ...
- C语言 第六章 多重循环练习
一.循环输入 #include "stdio.h" void main() { char c; do { printf("我告诉你1+1=2\n"); prin ...
- 1Z0-053 争议题目解析486
1Z0-053 争议题目解析486 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 486.You execute the following Recovery Manager (R ...
- 【JUC】JDK1.8源码分析之ReentrantReadWriteLock(七)
一.前言 在分析了锁框架的其他类之后,下面进入锁框架中最后一个类ReentrantReadWriteLock的分析,它表示可重入读写锁,ReentrantReadWriteLock中包含了两种锁,读锁 ...
- OpenCV2:等间隔采样和局部均值的图像缩小
图像的缩小从物理意义上来说,就是将图像的每个像素的大小缩小相应的倍数.但是,改变像素的物理尺寸显然不是那么容易的,从数字图像处理的角度来看,图像的缩小实际就是通过减少像素个数来实现的.显而易见的,减少 ...