用純css改變下拉列表select框的默認樣式


將瀏覽器默認的下拉框樣式清除,然后應用上自己的,再附一張向右對齊小箭頭的圖片即可。

 1 select {
 2 /*Chrome和Firefox里面的邊框是不一樣的,所以復寫了一下*/
 3   border: solid 1px #000;
 4 
 5 /*很關鍵:將默認的select選擇框樣式清除*/
 6   appearance:none;
 7   -moz-appearance:none;
 8   -webkit-appearance:none;
 9 /*在選擇框的最右側中間顯示小箭頭圖片*/
10   background: url("http://ourjs.github.io/static/2015/arrow.png") no-repeat scroll right center transparent;
11 /*為下拉小箭頭留出一點位置,避免被文字覆蓋*/
12   padding-right: 14px;
13 }
14 /*清除ie的默認選擇框樣式清除,隱藏下拉箭頭*/
15 select::-ms-expand { display: none; }

IE8/9並不支持  appearance:none  CSS屬性,想要支持的話可能需要非常特殊的方法,參考SF: 我們需要為其添加一個父容器,容器是用來覆蓋小箭頭的,然后為select添加一個向右的小偏移或者寬度大於父級元素。設置父級的CSS屬性為超出部分不可見,即可覆蓋即小箭頭。然后再為父級容器添加背景圖片即可。

1 <div id="parent">
2   <select>
3       <option>what</option>
4       <option>the</option>
5       <option>hell</option>
6   </select>
7 </div>
1 #parent {background: url('yourimage') no-repeat; width: 100px;
2 height: 30px; overflow: hidden;}
3 #parent select {background: transparent; border: none; padding-left: 10px; width: 120px; height: 100%;}

 input 背景透明代碼

background-color: transparent;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM