Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Select box arrow style

Tags:

I want to remove the default arrow from the select box and want to use custom icon. From the previous answers on SO, I have found out that it is not possible (to make it work with major browsers). Only possibility is to wrap the select inside a div, and set its width more than the div width and setting overflow: hidden. I am trying following, but it does not work. What I'm doing wrong?

.selectParent {
  width: 80px;
  overflow: hidden;
}

.selectParent select {
  width: 100px;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  padding: 2px 30px 2px 2px;
  border: none;
  background: transparent url("http://cdn1.iconfinder.com/data/icons/cc_mono_icon_set/blacks/16x16/br_down.png") no-repeat right center;
}
<div class="selectParent">
  <select>
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>           
   </select>
</div>

JSFiddle: http://jsfiddle.net/gcPmC/

like image 576
user1251698 Avatar asked Oct 01 '12 06:10

user1251698


People also ask

How do you style select box arrows?

The main trick is to apply appearance: none which lets you override some of the styling. It doesn't replace the OS select menu UI element so all the problems related to doing that are non-existant (not being able to break out of the browser window with a long list being the main one).

How do you change the arrow color on a select box?

Attach Inspector, press Ctrl+Shift+LMB on that arrow and you'll see what you should change.


1 Answers

Please follow the way like below:

.selectParent {
	width:120px;
	overflow:hidden;   
}
.selectParent select { 
	display: block;
	width: 100%;
	padding: 2px 25px 2px 2px; 
	border: none; 
	background: url("http://cdn1.iconfinder.com/data/icons/cc_mono_icon_set/blacks/16x16/br_down.png") right center no-repeat; 
	appearance: none; 
	-webkit-appearance: none;
	-moz-appearance: none; 
}
.selectParent.left select {
	direction: rtl;
	padding: 2px 2px 2px 25px;
	background-position: left center;
}
/* for IE and Edge */ 
select::-ms-expand { 
	display: none; 
}
<div class="selectParent">
  <select>
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>           
   </select>
</div>
<br />
<div class="selectParent left">
  <select>
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>           
   </select>
</div>
like image 101
Hanif Avatar answered Oct 27 '22 10:10

Hanif