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

How do you break a Monolith into Microservices at Scale? This ebook shows strategies and techniques for building scalable and resilient microservices.

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.

How do you break a Monolith into Microservices at Scale? This ebook shows strategies and techniques for building scalable and resilient microservices.

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}