Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container h-5/6 w-full flex flex-col justify-center items-center rounded-md">
  <img class="w-8 h-8 rounded-full" src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/d5/Tailwind_CSS_Logo.svg/2048px-Tailwind_CSS_Logo.svg.png">
  <h1 class="text-6xl mb-5 text-slate">Custom select <span class="text-sky">Tailwind style.</span></h1>
  <div class="relative md:w-2/6 sm:w-1/1 h-2/4 mt-5">
    <button type="button" name="cuvee" class="relative w-full py-2 pl-3 pr-10 text-left bg-white border border-gray-300 rounded-md shadow-sm cursor-default btn-popover focus:outline-none focus:ring-1 focus:ring-blue-400 focus:border-blue-400 sm:text-sm" aria-haspopup="listbox" aria-expanded="true" aria-labelledby="listbox-label">
      <span class="flex items-center">
        <img src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80" alt="" class="flex-shrink-0 w-6 h-6 rounded-full">
        <span class="block ml-3 truncate "> Tom Cook </span>
      </span>
      <span class="absolute inset-y-0 right-0 flex items-center pr-2 ml-3 pointer-events-none">
        <svg class="w-5 h-5 text-gray-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
          <path fill-rule="evenodd" d="M10 3a1 1 0 01.707.293l3 3a1 1 0 01-1.414 1.414L10 5.414 7.707 7.707a1 1 0 01-1.414-1.414l3-3A1 1 0 0110 3zm-3.707 9.293a1 1 0 011.414 0L10 14.586l2.293-2.293a1 1 0 011.414 1.414l-3 3a1 1 0 01-1.414 0l-3-3a1 1 0 010-1.414z" clip-rule="evenodd" />
        </svg>
      </span>
    </button>
    <ul class="absolute z-10 hidden w-full py-1 mt-1 overflow-auto text-base transition duration-100 ease-in bg-white border border-gray-300 rounded-md shadow-lg popover-list max-h-56 ring-1 ring-black ring-opacity-5 focus:outline-none sm:text-sm" tabindex="-1" role="listbox" aria-labelledby="listbox-label" aria-activedescendant="listbox-option-3">

      <li class="relative py-2 pl-3 text-white bg-blue-600 rounded-r-lg cursor-default select-none selected group pr-9 popover-item hover:text-white hover:bg-blue-600" id="popover-item-1" role="option">
        <div class="flex items-center">
          <img src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80" alt="" class="flex-shrink-0 w-6 h-6 rounded-full">

          <span class="block ml-3 font-normal truncate "> Tom Cook
          </span>
        </div>

        <span class="absolute inset-y-0 right-0 flex items-center pr-4 text-white group-hover:text-white">
          <svg class="w-5 h-5 " xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
            <path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd" />
          </svg>
        </span>
      </li>

      <li class="relative py-2 pl-3 text-gray-900 rounded-r-lg cursor-default select-none group pr-9 popover-item hover:text-white hover:bg-blue-600" id="popover-item-2" role="option">
        <div class="flex items-center">
          <img src="https://images.unsplash.com/photo-1491528323818-fdd1faba62cc?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80" alt="" class="flex-shrink-0 w-6 h-6 rounded-full">

          <span class="block ml-3 font-normal truncate "> Wade Cooper
          </span>
        </div>

        <span class="absolute inset-y-0 right-0 flex items-center pr-4 text-blue-600 group-hover:text-white">
          <svg class="hidden w-5 h-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
            <path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd" />
          </svg>
        </span>
      </li>

      <li class="relative py-2 pl-3 text-gray-900 rounded-r-lg cursor-default select-none group pr-9 popover-item hover:text-white hover:bg-blue-600" id="popover-item-3" role="option">
        <div class="flex items-center">
          <img src="https://images.unsplash.com/photo-1550525811-e5869dd03032?ixlib=rb-1.2.1&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80" alt="" class="flex-shrink-0 w-6 h-6 rounded-full">

          <span class="block ml-3 font-normal truncate "> Arlene McCoy
          </span>
        </div>

        <span class="absolute inset-y-0 right-0 flex items-center pr-4 text-blue-600 group-hover:text-white">
          <svg class="hidden w-5 h-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
            <path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd" />
          </svg>
        </span>
      </li>

      <li class="relative py-2 pl-3 text-gray-900 rounded-r-lg cursor-default select-none group pr-9 popover-item hover:text-white hover:bg-blue-600" id="popover-item-4" role="option">
        <div class="flex items-center">
          <img src="https://images.unsplash.com/photo-1500648767791-00dcc994a43e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2.25&w=256&h=256&q=80" alt="" class="flex-shrink-0 w-6 h-6 rounded-full">

          <span class="block ml-3 font-normal truncate "> Devon Webb
          </span>
        </div>

        <span class="absolute inset-y-0 right-0 flex items-center pr-4 text-blue-600 group-hover:text-white">
          <svg class="hidden w-5 h-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
            <path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd" />
          </svg>
        </span>
      </li>

      <li class="relative py-2 pl-3 text-gray-900 rounded-r-lg cursor-default select-none group pr-9 popover-item hover:text-white hover:bg-blue-600" id="popover-item-5" role="option">
        <div class="flex items-center">
          <img src="https://images.unsplash.com/photo-1494790108377-be9c29b29330?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80" alt="" class="flex-shrink-0 w-6 h-6 rounded-full">

          <span class="block ml-3 font-normal truncate "> Tanya Fox
          </span>
        </div>

        <span class="absolute inset-y-0 right-0 flex items-center pr-4 text-blue-600 group-hover:text-white">
          <svg class="hidden w-5 h-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
            <path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd" />
          </svg>
        </span>
      </li>

      <li class="relative py-2 pl-3 text-gray-900 rounded-r-lg cursor-default select-none group pr-9 popover-item hover:text-white hover:bg-blue-600" id="popover-item-6" role="option">
        <div class="flex items-center">
          <img src="https://images.unsplash.com/photo-1487412720507-e7ab37603c6f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80" alt="" class="flex-shrink-0 w-6 h-6 rounded-full">

          <span class="block ml-3 font-normal truncate "> Helen Schimdt
          </span>
        </div>

        <span class="absolute inset-y-0 right-0 flex items-center pr-4 text-blue-600 group-hover:text-white">
          <svg class="hidden w-5 h-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
            <path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd" />
          </svg>
        </span>
      </li>

      <li class="relative py-2 pl-3 text-gray-900 rounded-r-lg cursor-default select-none group pr-9 popover-item hover:text-white hover:bg-blue-600" id="popover-item-7" role="option">
        <div class="flex items-center">
          <img src="https://images.unsplash.com/photo-1568409938619-12e139227838?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80" alt="" class="flex-shrink-0 w-6 h-6 rounded-full">

          <span class="block ml-3 font-normal truncate "> Caroline Schultz
          </span>
        </div>

        <span class="absolute inset-y-0 right-0 flex items-center pr-4 text-blue-600 group-hover:text-white">
          <svg class="hidden w-5 h-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
            <path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd" />
          </svg>
        </span>
      </li>

      <li class="relative py-2 pl-3 text-gray-900 rounded-r-lg cursor-default select-none group pr-9 popover-item hover:text-white hover:bg-blue-600" id="popover-item-8" role="option">
        <div class="flex items-center">
          <img src="https://images.unsplash.com/photo-1531427186611-ecfd6d936c79?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80" alt="" class="flex-shrink-0 w-6 h-6 rounded-full">

          <span class="block ml-3 font-normal truncate "> Mason Heany
          </span>
        </div>

        <span class="absolute inset-y-0 right-0 flex items-center pr-4 text-blue-600 group-hover:text-white">
          <svg class="hidden w-5 h-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
            <path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd" />
          </svg>
        </span>
      </li>
    </ul>
  </div>

</div>
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css2?family=Inter:wght@800&display=swap");
html,
body {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 101vh;
  width: 100%;
}
.container {
  background: rgba(238, 242, 255);
  margin-left: auto;
  margin-right: auto;
  padding-left: 16px;
  padding-right: 16px;
}
h1 {
  font-family: "Inter", sans-serif;
}
.popover-list {
  scrollbar-color: rgb(185 207 255) transparent;
  scrollbar-width: thin;
}
.popover-list::-webkit-scrollbar {
  width: 20px;
}
.popover-list::-webkit-scrollbar-corner,
.popover-list::-webkit-scrollbar-track {
  background-color: transparent;
}
.popover-list::-webkit-scrollbar-thumb {
  background-color: rgb(147 197 253);
  border-radius: 20px;
  border: 6px solid transparent;
  background-clip: content-box;
}
.popover-list::-webkit-scrollbar-thumb:hover {
  background-color: rgb(37 99 235);
}
.text-sky {
  color: rgb(14 165 233);
}
.text-slate {
  color: rgb(15 23 42);
}

              
            
!

JS

              
                //function to check if click outside
function outsideClick(event, notelem) {
  notelem = $(notelem);
  var clickedOut = true,
    i,
    len = notelem.length;
  for (i = 0; i < len; i++) {
    if (event.target == notelem[i] || notelem[i].contains(event.target)) {
      clickedOut = false;
    }
  }
  if (clickedOut) return true;
  else return false;
}

//click away => close popover
var select = document.getElementsByClassName("btn-popover");
window.addEventListener("click", function (e) {
  if (outsideClick(e, select)) {
    if (typeof list !== "undefined") {
      //list.addClass('opacity-0').removeClass('opacity-1');

      //click  away -> reset all the selected style to selected item
      selected = document.getElementsByClassName("selected");
      text = selected[0];
      $(text).removeClass("text-gray-900").addClass("text-white bg-blue-600");
      $(text.children[0].children[1])
        .removeClass("font-normal")
        .addClass("font-semibold");
      $(text.children[1]).removeClass("text-blue-600").addClass("text-white");
      list.addClass("hidden");
      opened = 0;
    }
  }
});

//var used to check if popover is open or not => 0 closed, 1 opened
var opened;
$(".btn-popover").click(function () {
  btn = $(this);
  list = $(this).next();
  if (list.hasClass("hidden")) {
    opened = 1;
    list.removeClass("hidden");
  } else {
    opened = 0;
    list.addClass("hidden");
  }
});

$(".popover-item").click(function () {
  if (typeof btn !== "undefined") {
    if (opened === 1) {
      selectedItem = this;
      checkClasses(selectedItem);
    }
  }
});

function checkClasses(parentItem) {
  //remove any potential old marks
  parentItem = $(selectedItem).parent();
  //create array of the all the li
  liItems = $(parentItem).children("li").toArray();
  //remove the li clicked from the array
  liItems.splice($.inArray(selectedItem, liItems), 1);
  //loop through all the other li to check if there's a checkmark and selected style applied,if so remove it
  for (let i = 0; i < liItems.length; i++) {
    //apply unselected background color
    $(liItems[i])
      .addClass("text-gray-900")
      .removeClass("text-white bg-blue-600 selected");
    //apply unselected text color and style
    $(liItems[i].children[0].children[1])
      .addClass("font-normal")
      .removeClass("font-semibold");
    $(liItems[i].children[1])
      .addClass("text-blue-600")
      .removeClass("text-white");

    //delete checkmarck
    checkmark = $(liItems[i]).children().next();
    $(checkmark.find(">:first-child")).addClass("hidden");
  }
  addMark(selectedItem);
  addClasses(selectedItem);
}

function addClasses(selectedItem) {
  //add selected style, remove old style
  $(selectedItem)
    .removeClass("text-gray-900")
    .addClass("text-white bg-blue-600");
  $(selectedItem.children[0].children[1])
    .removeClass("font-normal")
    .addClass("font-semibold");
  $(selectedItem.children[1])
    .removeClass("text-blue-600")
    .addClass("text-white");
  opened = 1;
}

function addMark(selectedItem) {
  //clone selected  item and append it to the front popover
  newT = $(selectedItem).children().html();
  oldbtn = btn.find(">:first-child").fadeOut(70, function () {
    btn.find(">:first-child").html(newT).fadeIn(70);
  });

  //add svg mark + class selected
  checkmark = $(selectedItem).children().next();
  checkmark.find(">:first-child").removeClass("hidden");
  $(selectedItem).addClass("selected");
}

//When popover opened and li hovered deactivacte any selected style
$(".popover-item").on("mousemove", function () {
  if (opened == 1) {
    hoverItems = $(this).parent();
    //create array of the all the li
    hoverLiItems = $(hoverItems).children("li").toArray();
    for (let i = 0; i < hoverLiItems.length; i++) {
      $(hoverLiItems[i]).addClass("text-gray-900");
      $(hoverLiItems[i]).removeClass("text-white bg-blue-600");

      $(hoverLiItems[i].children[0].children[1]).addClass("font-normal");
      $(hoverLiItems[i].children[0].children[1]).removeClass("font-semibold");
      $(hoverLiItems[i].children[1]).addClass("text-blue-600");
      $(hoverLiItems[i].children[1]).removeClass("text-white");
    }
  }
});

              
            
!
999px

Console