Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Styling a Chosen select to fit Bootstrap 3 better

DZone's Guide to

Styling a Chosen select to fit Bootstrap 3 better

· Java Zone
Free Resource

Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code! Brought to you in partnership with ZeroTurnaround.

One project that I'm currently working on is an internal business application that's using stock Bootstrap 3. I needed a searchable select box and Chosen fitted the bill, so I'm using that.

However, the default styles for the Chosen select box differ slightly from Bootstrap. The most noticeable being the height of the control.

To fix this, I added this CSS:

.chosen-container-single .chosen-single {
    height: 30px;
    border-radius: 3px;
    border: 1px solid #CCCCCC;
}
.chosen-container-single .chosen-single span {
    padding-top: 2px;
}
.chosen-container-single .chosen-single div b {
    margin-top: 2px;
}

I also noticed that a focussed Bootstrap 3 element has a blue outline, but the Chosen select doesn't. To fix this, I added:

.chosen-container-active .chosen-single,
.chosen-container-active.chosen-with-drop .chosen-single {
    border-color: #ccc;
    border-color: rgba(82, 168, 236, .8);
    outline: 0;
    outline: thin dotted \9;
    -moz-box-shadow: 0 0 8px rgba(82, 168, 236, .6);
    box-shadow: 0 0 8px rgba(82, 168, 236, .6)
}

Before:
Chosen before

After:
Chosen after

Update: Brian Ridley pointed me at bootstrap-chosen which is much more comprehensive.

The Java Zone is brought to you in partnership with ZeroTurnaround. Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code!

Topics:

Published at DZone with permission of Rob Allen, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}