I'm trying to style a select
element using CSS3. I'm getting the results I desire in WebKit (Chrome / Safari), but Firefox isn't playing nicely (I'm not even bothering with IE). I'm using the CSS3 appearance
property, but for some reason I can't shake the drop-down icon out of Firefox.
Here's an example of what I'm doing: http://jsbin.com/aniyu4/2/edit
#dropdown {
-moz-appearance: none;
-webkit-appearance: none;
appearance: none;
background: transparent url('example.png') no-repeat right center;
padding: 2px 30px 2px 2px;
border: none;
}
As you can see, I'm not trying for anything fancy. I just want to remove the default styles and add in my own drop-down arrow. Like I said, great in WebKit, not great in Firefox. Apparently, the -moz-appearance: none
doesn't get rid of the drop-down item.
Any ideas? No, JavaScript is not an option
Update: this was fixed in Firefox v35. See the full gist for details.
Just figured out how to remove the select arrow from Firefox. The trick is to use a mix of
-prefix-appearance
,text-indent
andtext-overflow
. It is pure CSS and requires no extra markup.Tested on Windows 8, Ubuntu and Mac, latest versions of Firefox.
Live example: http://jsfiddle.net/joaocunha/RUEbp/1/
More on the subject: https://gist.github.com/joaocunha/6273016
building on the answer by @JoãoCunha, one css style that is usefull for more then one browser
I am styling the select just likes this
It works for me in FF, Safari and Chrome in all versions I've tested.
In IE I put:
Also you can: .yourclass::-ms-expand {display: none; } .yourid::-ms-exapan {display: none; }
We've found a simple and decent way to do this. It's cross-browser,degradable, and doesn't break a form post. First set the select box's
opacity
to0
.this is so you can still click on it
Then make div with the same dimensions as the select box. The div should lay under the select box as the background. Use
{ position: absolute }
andz-index
to achieve this.Update the div's innerHTML with javascript. Easypeasy with jQuery:
That's it! Just style your div instead of the select box. I haven't tested the above code so you'll probably need tweak it. But hopefully you get the gist.
I think this solution beats
{-webkit-appearance: none;}
. What browsers should do at the very most is dictate interaction with form elements, but definitely not how their initially displayed on the page as that breaks site design.A useful hack for me is to set the (selects) display to
inline-flex
. Cuts the arrow right out of my select button. Without all of the added code.-webkit appearance
still needed for Chrome, etc...The trick that works for me is to make select width more than 100% and apply overflow:hidden
This is the only way right now to hide dropdown arrow in FF.
BTW. if you want beautiful dropdowns use http://harvesthq.github.com/chosen/