May 23, 2014

Internet Explorer Select Dropdown Arrow Solution: ChosenJS

Browser testing can be one of the most daunting tasks for a web designer or developer, especially when that scope includes IE8 and IE9. Besides the usual background size and image fixes, the most difficult task to regulate is the dreaded select dropdown element. All browsers have their own default arrow on dropdown elements, unless specified otherwise by the CSS style sheet. In modern browsers ‚ Chrome, FireFox, Safari ‚ this is not a big deal and can simply be achieved with the following:

 border:none; -moz-appearance: none; -webkit-appearance: none; appearance: none; 

And in IE10 this actually isn’t too difficult to deal with either:

<pre><code>select::-ms-expand { display: none; } </code></pre>

IE9 and IE8 Are a Problem

However, when it comes to IE9 and IE8 the headache begins. None of the above CSS hacks can be seen by either browser. On smaller sites with less dropdown elements across the site, the simple method would be to use a wrapper on each select element and apply an overflow:hidden. Then set the select menu to 120% width of the wrapper, which in turn hides the dropdown arrow. Of course, you then run into problems with the child elements’ text being cut off and a few other nuisances that come with this method.

After having gone through a number of sites using the above method, I have finally found the best solution: ChosenJS.

Chosen is a library for making long, unwieldy select boxes more user-friendly. It takes the pain out of styling dropdown menus by searching for existing select elements on the page and replacing them with a more intuitive solution for the user and the developer. It’s easy to initialize, customize, and style.

The Solution

Enough rambling: I’ll show you how I made this plugin work with a site that had already been designed and styled completely with the assistance of the Bootstrap 3 framework and some helpful Chosen CSS overrides to make it Bootstrap 3 friendly. I am going to skip over the basic install steps for ChosenJS, and recommend that you read their documentation separately, and simply cut straight to the customization.

The site I was testing had the dropdown elements styled to perfection in modern browsers, so I decided to initialize ChosenJS in IE8 and IE9 only. I used the following snippet just before my closing tag in the footer:

<pre><code> </code></pre>

You’ll see here I am only targeting the select elements with the default bootstrap class —form-control,— and disabling the default search feature in ChosenJS since we simply didn’t need it. I also called the respective resources conditionally the same way in my header:

 <code><!--/!--[if lte IE 9]--> <link rel="stylesheet" href="/css/chosen.css"> <!--[endif]--//-->

I found this VERY helpful style sheet made specifically for those usingTwitter Bootstrap in addition to ChosenJS bootstrap CSS.

I simply stuck this style sheet to the bottom of my existing, default ChosenJS CSS, and all was well from then on ‚ well, with a few slight tweaks to colors and font sizes. The dropdown elements were identical in all browsers required by the client and I saved myself a few hours initially, and potentially days over the course of the next few years of browser testing. I hope you find this solution saves you time, too! Enjoy!

Paul Weinert
Author

Paul Weinert is our founder, managing principal and spirit animal. He’s one of those odd people you meet that was born in Portland, grew up here and still lives here for some reason. If you had two words to describe Paul after meeting him, we’d bet you’d use “charmingly quirky”.

Paul started GRAYBOX in February 2009, and for the first four years, GRAYBOX had a blend of a contract staffing firm and a traditional agency. GRAYBOX then hired our first employees in 2012 and has been growing ever since. Professionally, Paul has a background in internet business consulting, working especially with mid-market ecommerce, healthcare, and tech companies. He worked as a user experience designer, web developer and internet marketer. Nowadays, Paul serves as our company visionary, team mentor and head of executive leadership — Paul is extremely proud of the entire team and the company. He’s constantly humbled by the team’s awesomeness and the caring community that’s sprung up from his initial ideas.

Beyond GRAYBOX, Paul is married, has two young boys and lives in NE Portland. He’s also an active foster parent, mentors other local entrepreneurs, and volunteers on local non-profit boards. Businesswise, aside from GRAYBOX, Paul has started a few other businesses and is an active investor in the local startup scene.

For the sheer joy of it, let’s play 2 truths and a lie:

  1. Paul firmly believes that any activity would be better if on a boat.
  2. Other than this whole Internet thing, Paul has basically no other skills or expertise in anything.
  3. Paul is rare unicorn, actually born and raised in Portland.