Skip to content

Instantly share code, notes, and snippets.

@daz
Forked from kevindavis/gist:1868651
Last active May 13, 2023 11:24
Show Gist options
  • Select an option

  • Save daz/2168334 to your computer and use it in GitHub Desktop.

Select an option

Save daz/2168334 to your computer and use it in GitHub Desktop.
Bootstrap styling for jQuery UI autocomplete
.ui-autocomplete {
position: absolute;
top: 100%;
left: 0;
z-index: 1000;
float: left;
display: none;
min-width: 160px;
_width: 160px;
padding: 4px 0;
margin: 2px 0 0 0;
list-style: none;
background-color: #ffffff;
border-color: #ccc;
border-color: rgba(0, 0, 0, 0.2);
border-style: solid;
border-width: 1px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
-moz-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
-webkit-background-clip: padding-box;
-moz-background-clip: padding;
background-clip: padding-box;
*border-right-width: 2px;
*border-bottom-width: 2px;
.ui-menu-item > a.ui-corner-all {
display: block;
padding: 3px 15px;
clear: both;
font-weight: normal;
line-height: 18px;
color: #555555;
white-space: nowrap;
&.ui-state-hover, &.ui-state-active {
color: #ffffff;
text-decoration: none;
background-color: #0088cc;
border-radius: 0px;
-webkit-border-radius: 0px;
-moz-border-radius: 0px;
background-image: none;
}
}
}
@yrxwin

yrxwin commented Jul 30, 2016

Copy link
Copy Markdown

Thanks! for the last two blocks in .ui-autocomplete, here is my modification which works in my local Chrome

.ui-menu-item {
    display: block;
    padding: 3px 15px;
    clear: both;
    font-weight: normal;
    line-height: 18px;
    color: #555555;
    white-space: nowrap;

    .ui-state-active, .ui-state-hover {
      color: #ffffff;
      text-decoration: none;
      background-color: #0088cc;
      border-radius: 0;
      -webkit-border-radius: 0;
      -moz-border-radius: 0;
      background-image: none;
    }

  }

@shoesandsocks

Copy link
Copy Markdown

@yrxwin, your modification to the original is looking good here, thanks!

@webhacking

Copy link
Copy Markdown

Thank you!

@sheikhasadmuneer

Copy link
Copy Markdown

Thanks !!! 👍

@rolandszpond

Copy link
Copy Markdown

Minimal, out-of-the-box that mimics the drop-down styling while using Less...

.ui-autocomplete {
	.dropdown-menu;
}
.ui-state-hover,
.ui-state-active,
.ui-state-focus {
	a {
		text-decoration: none;
		color: @dropdown-link-hover-color;
		background-color: @dropdown-link-hover-bg;
		cursor: pointer;
	}
}

@lmcdougall

Copy link
Copy Markdown

Thanks!

This kind of works on my project. The selected item it get draw outside of the box and once the selection is made the string
stays on the screen. (rails 4.2.6, botstrap, simple_form)
Any suggestions ?

@em77

em77 commented Dec 23, 2016

Copy link
Copy Markdown

None of these seem to work as intended with the newest version of jquery-ui (1.12.1). They work with 1.11.4 though. If you're using rails, you can see how your gem matches up with the jquery-ui version here: https://github.com/jquery-ui-rails/jquery-ui-rails/blob/master/VERSIONS.md

@arturaum

Copy link
Copy Markdown

@em77 is right

Now this combination of selectors works (for me at least):

  .ui-menu-item-wrapper {
    display: block;
    padding: 3px 15px;
    clear: both;
    font-weight: normal;
    line-height: 18px;
    color: #555555;
    white-space: nowrap;

    &:hover, &.ui-state-focus, &.ui-state-active {
      color: #ffffff;
      text-decoration: none;
      background-color: #0088cc;
      border-radius: 0px;
      -webkit-border-radius: 0px;
      -moz-border-radius: 0px;
      background-image: none;
    }
  }

@bbonamin

bbonamin commented Dec 2, 2017

Copy link
Copy Markdown

On:

gem 'jquery-rails', '4.3.1'
gem 'jquery-ui-rails', '5.0.5' # which installs jquery-ui 1.11.4

The following worked for me perfectly:

.ui-autocomplete {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 1000;
  float: left;
  display: none;
  min-width: 160px;
  _width: 160px;
  padding: 4px 0;
  margin: 2px 0 0 0;
  list-style: none;
  background-color: #ffffff;
  border-color: #ccc;
  border-color: rgba(0, 0, 0, 0.2);
  border-style: solid;
  border-width: 1px;
  -webkit-border-radius: 5px;
  -moz-border-radius: 5px;
  border-radius: 5px;
  -webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
  -moz-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
  -webkit-background-clip: padding-box;
  -moz-background-clip: padding;
  background-clip: padding-box;
  *border-right-width: 2px;
  *border-bottom-width: 2px;

  .ui-menu-item {
    display: block;
    padding: 3px 15px;
    clear: both;
    font-weight: normal;
    line-height: 18px;
    color: #555555;
    white-space: nowrap;

    &.ui-state-focus, &.ui-state-active {
      color: #ffffff;
      text-decoration: none;
      background-color: #0088cc;
      border-radius: 0px;
      -webkit-border-radius: 0px;
      -moz-border-radius: 0px;
      background-image: none;
    }
  }
}

.ui-helper-hidden-accessible { display:none; } //Hide that pesky bottom message

@austinarchibald

Copy link
Copy Markdown

@bbonamin That is beautiful. Makes everything look soo much better! Thank you.

@mcunha98

Copy link
Copy Markdown

Thanks !!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment