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

將瀏覽器默認的下拉框樣式清除,而後應用上本身的,再附一張向右對齊小箭頭的圖片便可。git

 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屬性爲超出部分不可見,便可覆蓋即小箭頭。而後再爲父級容器添加背景圖片便可。github

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 背景透明代碼web

background-color: transparent;瀏覽器

相關文章
相關標籤/搜索