How to style <select>s using DropKick

Wdd Logo.
August 26, 2013
How to style <select>s using DropKick.

thumbnailWhen it comes to styling webpages, nothing's as tricky as forms. And when it comes to styling forms — almost — nothing's as tricky as the <select> input.

We can style a <select> with CSS, but there are big limitations on how much we can achieve with CSS alone. Often, the only viable option is styling via JavaScript, and as a form of progressive enhancement it's not something we need to shy away from.

In this article we'll be using DropKick to create out dropdown. What dropkick does is transform the <select> list into a fully customizable HTML dropdown and when one option is selected the corresponding select value will be updates as part of your form. OK, let's get started then…

Setting up our <select>

The first thing we need to do is set up a <select>, we'll create one for the business days in the week:

<select id='mySelect'>
<option value='mon'>Monday</option>
<option value='tue'>Tuesday</option>
<option value='wed'>Wednesday</option>
<option value='thu'>Thursday</option>
<option value='fri'>Friday</option>
</select>

Calling DropKick

Once we've set up our <select> we need to load three files into our document: the JavaScript DropKick file, the CSS, and of course jQuery. We should load the CSS in the head and JavaScripts at the foot of the page. With that done, all we need to do to activate the plugin and create our fully customizable dropdowns is to call DropKick, like so:

$('#mySelect').dropkick();

By doing so we transform our HTML into this:

<div class="dk_container dk_theme_default" id="dk_container_undefined">
<a class="dk_toggle">
<span class="dk_label">Thursday</span>
</a>
<div class="dk_options">
<ul class="dk_options_inner">
<li class="">
<a data-dk-dropdown-value="mon">Monday</a>
</li>
<li class="">
<a data-dk-dropdown-value="tue">Tuesday</a>
</li>
<li class="">
<a data-dk-dropdown-value="wed">Wednesday</a>
</li>
<li class="dk_option_current">
<a data-dk-dropdown-value="thu">Thursday</a>
</li>
<li class="">
<a data-dk-dropdown-value="fri">Friday</a>
</li>
</ul>
</div>
</div>

As you can see, DropKick has transformed our <select> into something we can be confident of styling with CSS. Furthermore, our values have been inserted in the new HTML5 data attributes (with the name data-dk-dropdown-value).

We can now style our dropdown with CSS, or use one the DropKick's themes if we prefer; at the time of writing there are three themes available, the default, dark gloss and light gloss. But most people will want to use their own styles that match their project's needs.

Extending DropKick

Extending DropKick is a simple process. For example, if we wanted to detect when a change is made to the dropdown, we can add the change event handler, like so:

$('select').dropkick({
change: function (value) {
console.log('Option selected: ' + value);
}
});

Final thoughts

I'm sure there are a thousand ways to style a select menu without the use of jQuery, but the ones that use just CSS are fighting a losing battle against the browser's defaults. The simplicity of this plugin and the tremendous flexibility it offers and the progressive enhancement approach that it takes means DropKick is an excellent solution.

Have you used DropKick in a project? Do you have a preferred method of styling <select>s? Let us know in the comments.

WDD Staff

WDD staff are proud to be able to bring you this daily blog about web design and development. If there's something you think we should be talking about let us know @DesignerDepot.

Read Next

3 Essential Design Trends, November 2024

Touchable texture, distinct grids, and two-column designs are some of the most trending website design elements of…

20 Best New Websites, October 2024

Something we’re seeing more and more of is the ‘customizable’ site. Most often, this means a button to swap between…

Exciting New Tools for Designers, October 2024

We’ve got goodies for designers, developers, SEO-ers, content managers, and those of you who wear multiple hats. And,…

15 Best New Fonts, September 2024

Welcome to our roundup of the best new fonts we’ve found on the web in the previous four weeks. In this month’s edition…

3 Essential Design Trends, October 2024

This article is brought to you by Constantino, a renowned company offering premium and affordable website design You…

A Beginner’s Guide to Using BlueSky for Business Success

In today’s fast-paced digital world, businesses are always on the lookout for new ways to connect with their audience.…

The Importance of Title Tags: Tips and Tricks to Optimize for SEO

When it comes to on-page SEO, there’s one element that plays a pivotal role in both search engine rankings and user…

20 Best New Websites, September 2024

We have a mixed bag for you with both minimalist and maximalist designs, and single pagers alongside much bigger, but…

Exciting New Tools for Designers, September 2024

This time around we are aiming to simplify life, with some light and fast analytics, an all-in-one productivity…

3 Essential Design Trends, September 2024

September's web design trends have a fun, fall feeling ... and we love it. See what's trending in website design this…

Crafting Personalized Experiences with AI

Picture this: You open Netflix, and it’s like the platform just knows what you’re in the mood for. Or maybe you’re…

15 Best New Fonts, August 2024

Welcome to August’s roundup of the best fonts we’ve found over the last few weeks. 2024’s trend for flowing curves and…