<input type="file">標簽自帶的上傳按鈕是無法改變樣式,如果不需要顯示上傳按鈕的路徑,可以做如下處理:
1、設置input的font-size大小為想要的大小;
2、設置input的透明度為0;
3、為其父元素定義樣式;
4、
DEMO:
<!DOCTYPE html>
<html>
<head>
<style>
.fileInputContainer{
height:256px;
background:url(http://images.cnblogs.com/cnblogs_com/dreamback/437546/o_ff6.png);
position:relative;
width: 256px;
}
.fileInput{
height:256px;
overflow: hidden;
font-size: 300px;
position:absolute;
right:0;
top:0;
opacity: 0;
filter:alpha(opacity=0);
cursor:pointer;
}
</style>
</head>
<body>
<div class="fileInputContainer">
<input class="fileInput" type="file" name="" id="" />
</div>
</body>
</html>
另外一種方法是:
1、單獨樣式和上傳文件的input(將input隱藏到頁面之外,或者將其opacity設置為0)
2、單獨定義一個容器存放上傳的文件的路徑
DEMO:
<!DOCTYPE html>
<html>
<head>
<style>
.fileInput{width:102px;height:34px; background:url(http://images.cnblogs.com/cnblogs_com/dreamback/upFileBtn.png);overflow:hidden;position:relative;}
.upfile{position:absolute;top:-100px;}
.upFileBtn{width:102px;height:34px;opacity:0;filter:alpha(opacity=0);cursor:pointer;}
</style>
</head>
<body>
<div class="fileInput left">
<input type="file" name="upfile" id="upfile" class="upfile" onchange="document.getElementById('upfileResult').innerHTML=this.value"/>
<input class="upFileBtn" type="button" value="上傳圖片" onclick="document.getElementById('upfile').click()" />
</div>
<span class="tip left" id="upfileResult">圖片大小不超過2M,大小90*90,支持jpg、png、bmp等格式。</span>
</body>
</html>