HTML控件篇 -- input
1. 取消input提示框及自动填充:
<input type="text" autocomplete="off" />
处理chrome下自动填充黄底样式问题:
/*input样式特殊处理*/
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
-webkit-appearance: none;
} input:-webkit-autofill {
-webkit-box-shadow: 0 0 0 1000px white inset;
}
2. 默认input提示语兼容处理:
<input type="text" placeholder="请输入内容" />
处理低版本IE浏览器placeholder不兼容方法:
添加如下Javascript:
$(function(){
if(!placeholderSupport()){ // 判断浏览器是否支持 placeholder
$('[placeholder]').focus(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
input.removeClass('placeholder');
}
}).blur(function() {
var input = $(this);
if (input.val() == '' || input.val() == input.attr('placeholder')) {
input.addClass('placeholder');
input.val(input.attr('placeholder'));
}
}).blur();
};
})
function placeholderSupport() {
return 'placeholder' in document.createElement('input');
}
添加如下CSS:
input.placeholder{
color:#aaaaaa;
}
3. 上传控件美化/添加手型
通常情况下,<input type='file'>是不支持常规添加手型的效果的,即添加样式cursor:pointer;
同时,input,type=file在不同浏览器下表现的样式也是多种多样的,如下:

图片摘自kukei的《HTML之上传控件“input=file”的美化》,他的文章中清楚的说明了美化input,type=file控件,
这里就不再重复。这里要提的是,如何为input=file添加手型样式,
因为在不同的浏览器下出现各种差异,所以在浏览器上表现也不同,例如:
在IE下:如果给input加上(cursor:pointer),那么左边输入框和右边的浏览按钮都会出现鼠标移动上去有手型;
chrome下:如果给input加(cursor:pointer),那么只有右边的输入框即上图的(No file chosen)部分有手型,按钮区域则不会出现手型。
并且通常情况下,我们会对inputfile进行美化,去掉右边的输入框,所以,出现了IE下有手型,chrome下没手型的问题。一下来解决这个问题。
直接上代码(不清楚的看看kukei的美化博客):
HTML代码:
<div class='div-upload'>
<input type="file">选择文件
</div>
CSS代码:
.div-upload {
padding: 4px 10px;
height: 20px;
line-height: 20px;
position: relative;
cursor: pointer;
color: #888;
background: #fafafa;
border: 1px solid #ddd;
border-radius: 4px;
overflow: hidden;
display: inline-block;
*display: inline;
*zoom: 1
}
.div-upload input {
position: absolute;
font-size: 100px;
right:;
top:;
opacity:;
filter: alpha(opacity=0);
cursor: pointer
}
.div-upload:hover {
color: #444;
background: #eee;
border-color: #ccc;
text-decoration: none
}
效果:

- -!截图的时候鼠标看不见。反正是实现了。下面说一下个性css样式及原理。
这个例子中,就是在input,type=file外层套了一个div,设置position:relative;cursor:pointer(其他样式纯属喜好)
.div-upload {
position: relative;
cursor: pointer;
/*height: 20px;
line-height: 20px;
color: #888;
background: #fafafa;
border: 1px solid #ddd;
border-radius: 4px;
overflow: hidden;
display: inline-block;
*display: inline;
*zoom: 1*/
}
然后设置input为绝对位置,透明position:absolute;opacity: 0;filter: alpha(opacity=0);然后是个重要的:位置对其:top:0;right:0;
.div-upload input {
position: absolute;
font-size: 100px;
right:;
top:;
opacity:;
filter: alpha(opacity=0);
cursor: pointer
}
这样,就实现了给input,type=file控件添加移动上去手型的样式。
HTML控件篇 -- input的更多相关文章
- swift系统学习控件篇:UIbutton+UIlabel+UITextField+UISwitch+UISlider
工作之余,学习下swift大法.把自己的学习过程分享一下.当中的布局很乱,就表在意这些细节了.直接上代码: UIButton+UILabel // // ViewController.swift // ...
- input绑定datapicker控件后input再绑定blur或者mouseout等问题
input绑定datapicker控件后input再绑定blur或者mouseout等问题 问题描述:今天在修改一个东西的时候需要给一个input输入域绑定blur事件,从而当它失去焦点后动态修改其中 ...
- 一步一步学android之控件篇——ScrollView
一个手机的屏幕大小是有限的,那么我要显示的东西显示不下怎么办?这就会使用到ScrollView来进行滚动显示,他的定义如下: 可以看到ScrollView是继承于FrameLayout的,所以Scro ...
- Bootstrap系列 -- 14. 表单控件输入框input
每一个表单都是由表单控件组成.离开了控件,表单就失去了意义.接下来的我们简单的来了解Bootstrap框架中表单控件的相关知识. 单行输入框,常见的文本输入框,也就是input的type属性值为tex ...
- swift系统学习控件篇:UIProgressView+NSTimer+UIstepper+UIAlertController
工作之余,学习下swift大法.把自己的学习过程分享一下.当中的布局很乱,就表在意这些细节了.直接上代码: UIProgressView+NSTimer+UIstepper UIStepper UIP ...
- jQuery Mobile里xxx怎么用呀?(控件篇)
jQuery Mobile里都有什么控件? http://api.jquerymobile.com/category/widgets/ jQuery Mobile里slider控件的change事件怎 ...
- openlayers4 入门开发系列之地图导航控件篇(附源码下载)
前言 openlayers4 官网的 api 文档介绍地址 openlayers4 api,里面详细的介绍 openlayers4 各个类的介绍,还有就是在线例子:openlayers4 官网在线例子 ...
- android--------自定义控件 之 组合控件篇
上篇介绍了自定义控件的自定义属性篇,地址:http://www.cnblogs.com/zhangqie/p/8969163.html 这篇博文主要来说说 自定义控件的组合控件来提高布局的复用 使用自 ...
- VUE实现Studio管理后台(十三):按钮点选输入控件,input输入框系列
按钮点选输入,是一个非常简单的控件,20分钟就能完成的一个控件.先看效果: 根据以前的设定,通过json数据动态生成这两个按钮,示例中这两个按钮对应的json代码: { label:'标题', val ...
随机推荐
- 38. Same Tree && Symmetric Tree
Same Tree Given two binary trees, write a function to check if they are equal or not. Two binary tre ...
- Tomcat 常用配置
1.Tomcat 管理员设置 想要进入Tomcat管理界面: 打开Tomcat 目录 :进入 Conf目录,找到tomcat-users.xml文件,打开 修改 tomcat-users 节, 2.T ...
- Linux下多线程,断点续传,命令行下载工具axel
From: http://www.2cto.com/os/201202/118482.html 安装办法: $ sudo pacman -S axel 使用方法: $ axel -n 10 -o /文 ...
- 异步SRAM控制器的Verilog建模
前言:sram顾名思义静态随机存储器,分为asram异步型和ssram同步型.这里驱动DE2上一块ISSI公司的512KB的asram. 设计思路:因为实际应用中单字节读写效率不高,所以本设计中仿照s ...
- 北京市小升初 zz
发信人: django (牛魔王), 信区: SchoolEstate 标 题: 北京市小升初掐尖方式的演变过程(看后恍然大悟) 发信站: 水木社区 (Thu Feb 4 10:51:23 201 ...
- .NET 扩展方法
.NET 的扩展方法是在.NET 3.0引入的,MSDN给出的定义是:扩展方法使你能够向现有类型“添加”方法(包括你自定义的类型和对象噢),而无需创建新的派生类型.重新编译或以其他方式修改原始类型.扩 ...
- 【EF学习笔记05】----------操作内存中的数据
SingleOrDefault实验 //SingleOrDefault实验 using (var db = new Entities()) { var classes = new Classes() ...
- linux 修改ssh端口号
vi /etc/ssh/sshd_config 找到#Port 22一段,这里是标识默认使用22端口,修改为如下: 代码如下 复制代码 Port 22 Port 50000 然后保存退出 执行/et ...
- 『GreenPlum系列』GreenPlum 4节点集群安装(图文教程)
目标架构如上图 一.硬件评估 cpu主频,核数推荐CPU核数与磁盘数的比例在12:12以上Instance上执行时只能利用一个CPU核资源进行计算,推荐高主频 内存容量 网络带宽重分布操作 R ...
- linux C学习笔记01--makefile
不知不觉毕业五年了,以前学的linux基本都忘了,重新温习起来吧! 下面是自己写的makefile文件,供新手和自己回头时查阅 CC=gcc EXE=c.out CCC=g++ EEE=cc.out ...