Try Tuts+ Premium, Get Cash Back!
Styling Dark Select Dropdown With Dropkick.js
videos

Styling Dark Select Dropdown With Dropkick.js

Tutorial Details
  • Topic: Site elements
  • Difficulty: Intermediate
  • Screencast duration: 30 mins
This entry is part 11 of 11 in the Bringing Premium Pixels to Life Session
« Previous

HTML select elements with their option tags cannot be completely customized using CSS, but what if we want to style a dropdown just as easily as <div>, <a>, <ul>, and <li> elements can be styled? Today, we’ll style the Premium Pixels Dark Select Dropdown using DropKick.js to help us do just that.


View Screencast

Alternatively, Download the video, or subscribe to Webdesigntuts+ screencasts via iTunes or YouTube!

Here is a basic outline of what’s covered in this screencast:


Step 1: Base HTML and CSS

First, we will start off with our base HTML and CSS. The HTML will consist of a simple select tag and options in respective option tags. To start off with a clean slate, we will be using normalize.css. Nothing fancy here, we just want to start everything off – stay tuned for the fun stuff!

<!DOCTYPE html>
<!--[if lt IE 7 ]><html class="ie ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--><html lang="en"> <!--<![endif]-->
<head>
	<meta charset="utf-8">
	<title>Dark Select</title>
	<meta name="description" content="">
	<meta name="author" content="">
	<!-- Don't Forget the Viewport Metatag http://enva.to/A79s3G -->
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<!-- CSS -->
	<link rel="stylesheet" href="css/normalize.css">
	<!--[if lt IE 9]>
		<script src="https://html5shim.googlecode.com/svn/trunk/html5.js"></script>
	<![endif]-->
</head>
	<body>
		<select name="dropdown" class="dropdown">
			<option>Settings...</option>
			<option>Your profile</option>
			<option>Your account</option>
			<option>Notifications</option>
			<option>Sign Out</option>
		</select>
	</body>
</html>

Step 2: Setting Up DropKick.js

DropKick.js is a great tool to treat select and option tags just like other tags that are a lot easier to style in CSS (e.g. unordered lists styled as navigation bar). Converting the HTML structure into a series of div’s,a’s, ul’s and li’s, styling dropdowns is as simple as customizing a theme template (which DropKick.js provides).

Implementing DropKick.js is as straight forward as executing a line of jQuery. We will start off downloading DropKick.js and altering our HTML to fit the script’s requirements (adding a name and class attribute to the select element) as well as extracting the CSS for the dropdown theme.


Step 3: Implementing DropKick.js

Using DropKick.js’s default template, we will be adding the necessary jQuery to bring the drop down to life. DropKick.js has many other features including callback events, but we will be focusing on the theme customization during this tutorial.

    // HTML template for the dropdowns
    dropdownTemplate = [
      '<div class="dk_container" id="dk_container_{{ id }}" tabindex="{{ tabindex }}">',
        '<a class="dk_toggle">',
          '<span class="dk_label">{{ label }}</span>',
        '</a>',
        '<div class="dk_options">',
          '<ul class="dk_options_inner">',
          '</ul>',
        '</div>',
      '</div>'
    ].join(''),

Step 4: Customizing a DropKick.js Theme

DropKick.js makes it very easy to make a custom theme for select dropdowns and we’ll be using Premium Pixels’ great dark design for this tutorial. In order to duplicate our design, we will be adding a bit of code to the javascript file.


Step 5: Scaling With Font Size

Lets face it – nothing is worse than struggling to select something extremely small using a mobile touch device (Ed: I can think of a few things..) The fix? Using font size (em’s) to scale the dropdown. Instead of using images for the dropdown arrows, we will be using a webfont (Font Awesome), which allows for much greater flexibility.


Conclusion

Styling form elements can be a pain, but using DropKick.js combined with a great design, it only takes a couple of minutes to implement and customize a great looking select dropdown.

Suhail Dawood is sdproductions on Videohive
Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://terencedevine.com Terence

    Dropkick is one of the best plugins to style select dropdowns that I’ve found, but when you have too many options available and it adds the scroll bar, it doesn’t work properly in IE7, IE8 AND IE9! Check out the ‘Pick a State’ select dropdown on the plugin page http://jamielottering.github.com/DropKick/

  • Sigilist

    This is excellent for selects, but when it comes to “Styling form elements can be a pain,” this isn’t the answer. Imagine this approach for every type of element that can appear inside a “form.” The amount of code would be ridiculous. Styling forms for adaptability needs start from the and work downward across elements together where possible… not the subelements individually and then upward.

    I would still use this on some very minimalist forms of one or two selects, for it is very nice, but that’s all.

    • http://www.snaptin.com Ian Yates

      Absolutely, good point! Various form elements can be awkward to style consistently, but that doesn’t mean this is the answer to everything! It’s a cool solution to some situations.

  • http://www.fetr.net fetr

    very nice

    • http://www.suhaildawood.com Suhail Dawood
      Author

      Glad you enjoyed it!

  • Ankur

    Tut is good but Dropkick is not good enough if you want to implement this as replacement for customized select. This gives a lot of problems while working with call back functions.

    One of the major problem is in that drop down if you want to immediately select one option using your keyboard it will not work, and this create major problem while working in a very long listing for example country list, if you want to get to india you will press I immediately, but dropkick doesn’t support this and do nothing.

    Anyway nice tut :) keep it up..

    • http://www.suhaildawood.com Suhail Dawood
      Author

      I’m glad you enjoyed the tutorial! As for your comments, I agree. Even though you can still use the arrow keys to navigate, pressing letters does not work. If you want to integrate a dropdown that allows you to search, here (http://www.onemoretake.com/2011/04/17/a-better-jquery-ui-combo-box/) is a great way using jQuery UI.

  • http://www.lkenneth.co.uk Liam Kenneth

    Whoo hoo! wish I heard about this months ago I always struggle trying to make fancy drop downs. Does Dropkicks handle Check box styling?

  • Pingback: Free Dropdown jQuery Menu Plugin « Web css jquery

  • Pingback: Custom Dropdown with custom scrollbar

  • http://twitter.com/lukeswg Lucas Schvindt

    Beautiful. Only problem is, it doesn’t seem to work with jQuery 1.9.1