碰到个页面的美化问题,效果图如下:
而html默认的空间是难看的,就像下面这个优快云编辑博客的苦逼控件一样:
那么就需要我们来解决,我的方法是使用text与button代替这个控件,使用了覆盖的实现方式,不多说,看代码:
<div class="secend">
<p>选择文件</p>
<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='btn1' 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="btn2" value="上传" />
<input type="button" name="submit" class="btn3" value="重置" />
</form>
</div>
</div>
.file-box{ position:relative;width:600px}
.txt{ height:30px; border:1px solid #cdcdcd; width:500px;}
.btn1{color: white; background-color:#FFF; border:1px solid #CDCDCD;height:32px; width:90px;background-color: #2688C1;}
.btn2{color: white; background-color:#FFF; border:1px solid #CDCDCD;height:50px; width:110px;background-color: #56cf86;margin-top: 2%;margin-right: 0.5%}
.btn3{ background-color:#FFF; border:1px solid #CDCDCD;height:50px; width:110px;background-color: #ececec;margin-top: 2%;}
.btn1:hover,.btn2:hover,.btn3:hover{opacity: 0.7;}
.file{ position:absolute; top:0; height:30px; filter:alpha(opacity:0);opacity: 0;width:600px }
目前存在的问题是:“浏览”按钮点击没有交互,因为实际上点击的是file控件,那么如何解决这个问题呢?
希望以后可以找到答案,渴望各路大神提点