读书人

定义input type=quot;filequot; 的式样

发布时间: 2012-07-01 13:15:00 作者: rapoo

定义input type="file" 的样式

原始的file控件是这么写的:

<input type="file" name="file" />

?比较丑。它在外观上是由一个text和一个button组合成的,实际是一个控件

既然这样我们就用一个text和一个button来显示这个file的样式,html代码是这样:

<form action="" method="post" enctype="multipart/form-data"><div name="fileField" id="fileField" size="28" onchange="document.getElementById('textfield').value=this.value" /><input type="submit" name="submit" value="上传" /></div></form>

?

外面的一层div是为了给里面的input提供位置参考,因为写样式的时候需要相对定位,使真正的file控件覆盖在模拟的上面,然后隐藏掉file控件(即使file控件不可见),所以css代码是这样的:

<style>.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>

?

效果图:
定义input type=

?

?

读书人网 >Web前端

热点推荐