因爲明天公司組織出去遊玩,今天把這兩天的博客都寫了吧,今天的內容是input[type=file] 樣式美化,input上傳按鈕美化。javascript
咱們在作input文本上傳的時候,html自帶的上傳按鈕比較醜,如何對其進行美化呢?同理:input checkbox美化,input radio美化是一個道理的,後面文章會總結。html
input file上傳按鈕的美化思路是,先把以前的按鈕透明度opacity設置爲0,而後,外層用div包裹,就實現了美化功能。java
代碼以下:spa
DOM結構:code
<a href="javascript:;" class="a-upload"> <input type="file" name="" id="">點擊這裏上傳文件 </a> <a href="javascript:;" class="file">選擇文件 <input type="file" name="" id=""> </a>
CSS樣式1:htm
/*a upload */ .a-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 } .a-upload input { position: absolute; font-size: 100px; right: 0; top: 0; opacity: 0; filter: alpha(opacity=0); cursor: pointer } .a-upload:hover { color: #444; background: #eee; border-color: #ccc; text-decoration: none }
樣式2:ip
.file { position: relative; display: inline-block; background: #D0EEFF; border: 1px solid #99D3F5; border-radius: 4px; padding: 4px 12px; overflow: hidden; color: #1E88C7; text-decoration: none; text-indent: 0; line-height: 20px; } .file input { position: absolute; font-size: 100px; right: 0; top: 0; opacity: 0; } .file:hover { background: #AADFFD; border-color: #78C3F3; color: #004974; text-decoration: none; }
修改後以下:ci
樣式二:input