定义input type=file 样式的方法
来源:互联网 发布:stc15系列单片机 编辑:程序博客网 时间:2024/06/09 22:41
原始的file控件是这样的:
<input type="file" name="file" />
既然这样我们就用一个text和一个button来显示这个file的样式,html代码是这样:
<div class="file-box"> <form action="" method="post" enctype="multipart/form-data"> <input type='text' name='textfield' id='textfield' class='txt' /> <input type='button' class='btn' value='浏览...' /> <input type="file" name="fileField" class="file" id="fileField" size="28" onchange="document.getElementById('textfield').value=this.value" /> <input type="submit" name="submit" class="btn" value="上传" /> </form> </div>
外面的一层div是为了给里面的input提供位置参考,因为写样式的时候需要相对定位,使真正的file控件覆盖在模拟的上面,然后隐藏掉file控件(即使file控件不可见),所以css代码是这样的:
.file-box{ position:relative;width:340px} .txt{ height:22px; border:1px solid #cdcdcd; width:180px;} .btn{ background-color:#FFF; border:1px solid #CDCDCD;height:24px; width:70px;} .file{ position:absolute; top:0; right:80px; height:24px; filter:alpha(opacity:0);opacity: 0;width:260px }
完整代码:
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>定义input type="file" 的样式</title><style type="text/css">body{ font-size:14px;}input{ vertical-align:middle; margin:0; padding:0}.file-box{ position:relative;width:340px}.txt{ height:22px; border:1px solid #cdcdcd; width:180px;}.btn{ background-color:#FFF; border:1px solid #CDCDCD;height:24px; width:70px;}.file{ position:absolute; top:0; right:80px; height:24px; filter:alpha(opacity:0);opacity: 0;width:260px }</style></head><body><div class="file-box"> <form action="" method="post" enctype="multipart/form-data"> <input type='text' name='textfield' id='textfield' class='txt' /> <input type='button' class='btn' value='浏览...' /> <input type="file" name="fileField" class="file" id="fileField" size="28" onchange="document.getElementById('textfield').value=this.value" /> <input type="submit" name="submit" class="btn" value="上传" /> </form></div></body></html>
- 定义input type=file 样式的方法
- 定义input type=file 样式的方法
- 定义input type=file 样式的方法
- 定义input type=file 样式的方法
- 定义input type=file 样式的方法
- html定义input type=file 样式的方法
- 定义input type=file 样式的方法
- 定义input type=file 样式
- 定义input type=file 样式的方法,使用一个text和一个button模拟
- 定义input type=file 样式的方法,使用一个text和一个button模拟
- type=file的input框样式修改的方法
- [JS实例] input type=file 自定义样式的方法
- input type="file" 样式的模仿
- input[type="file"]的样式修改
- 自定义input[type=”file”]的样式
- input,type="file"的样式修改
- 美化input type="file"的样式
- 定义input type=file
- proteus7 和 keil4 仿真流水灯
- php curl 打开https网站
- ASF文件格式详解(1)
- Lua string 处理
- 注册表的文件类型关联
- 定义input type=file 样式的方法
- ASF文件格式详解(2)
- linux ptrace函数
- Win8 IE10浏览器全方位解析
- cin.get( )与cin.getline( )的区别
- SVN分支和合并
- Axis2+Tomcat 官方实现WebService
- 防止SQL注入的参数化方法
- px和pt的区别