Form elements have always allowed limited styling…which is why I hate working on form display.  And I started when form elements were virtually unstylable back in the Internet Explorer 4 days.  Of course we’ve come a long way but there’s one element which is still somewhat difficult to style and isn’t particularly elegant:  SELECT.  The element looks different from OS to OS and sometimes even browser to browser — not ideal.

I recently found an awesome jQuery plugin to make the SELECT element more presentable, elegant, and stylable:  Quick[select].  Quick[select] turns SELECT options into clickable buttons with a traditional SELECT as a fallback.

The CSS

Quick[select] comes with a base stylesheet but you can style the option “buttons” in any way you’d like, as you can see in my demo.  Here are my basic styles:

.btn-group .btn {
	border: 1px solid #ccc;
	background: #eee;
	padding: 4px;
	border-radius: 4px;
	margin: 0 10px 0 0;
	font-size: 14px;
	display: inline;

	transition: background .3s, border-color .3s;
}
.btn-group .btn.active {
	background: #7ac9ed;
	border-color: #0c7bb6;
}

Quick[select] also has a helper for bootstrapped-driven sites, if that’s your stack.

The JavaScript

Using Quick[select] is easy:  add the plugin to the page and then use the jQuery plugin syntax to create instances for given SELECT elements:

jQuery('#wakeup-time').quickselect({
	activeButtonClass: 'btn-primary active',
	breakOutValues: ['06:30', '07:00', '07:30', '08:00'],
	buttonClass: 'btn btn-default',
	selectDefaultText: 'Other',
	wrapperClass: 'btn-group'
});

The most important option is breakOutValues which generates clickable buttons for popular choices (specified by you) within the SELECT element.  You’ll also want to set a custom selectDefaultText value for when the button which triggers the full display of the options.

Quick[select] is the best SELECT alternative that I’ve seen in a long time.  This plugin allows for elegant, stylish, and usable SELECT elements.  Go check it out and do your users a favor!

Source: David Walsh

Leave a Reply