JSFiddle - React, Tailwind, and code Playground
HTML
<section>
<select>
<option value="1">First</option>
<option value="2">Second</option>
<option value="3">Third</option>
<option value="4">Fourth</option>
<option value="5">Fifth</option>
<option value="6">Sixth</option>
</select>
</section>
CSS
body { font-size: 16px; line-height: 1.5; }
section { margin: 20% auto; max-width: 80%; }
* { padding: 0; }
/*plugin css*/
.custom-select-wrapper {
display: block;
position: relative;
border-bottom: 2px solid #323232;
min-height: 1em;
font-size: 2em;
background-color: transparent;
cursor: pointer;
width: 100%;
max-width: 90%;
margin: 0 auto;
}
.custom-select-wrapper SELECT {
display: none;
}
.custom-select-wrapper .pointer {
position: absolute;
left: auto;
right: 0;
bottom: 0;
top: 5px;
font-size: .5em;
}
.custom-select-display {
display: block;
text-align: center;
border: none;
background-color: transparent;
max-width: 100%;
width: 100%;
outline: none;
cursor: pointer;
font-size: .8em;
}
.custom-select-display::-moz-selection, .custom-select-display::selection {
color: transparent;
background-color: transparent;
cursor: pointer;
}
.custom-select-options {
list-style: none;
display: block;
opacity: 0;
position: absolute;
top: 0;
bottom: auto;
left: 0;
right: 0;
background-color: white;
outline: none;
z-index: -1;
text-align: center;
-moz-transition: z-index .1s ease, opacity .4s ease;
-o-transition: z-index .1s ease, opacity .4s ease;
-webkit-transition: z-index .1s ease, opacity .4s ease;
transition: z-index .1s ease, opacity .4s ease;
}
.custom-select-options.open {
z-index: 1;
opacity: 1;
box-shadow: 1px 1px 5px 0px #ABABAB;
}
.custom-select-option {
display: block;
}
.custom-select-option.active,
.custom-select-options.open .custom-select-option:hover {
background-color: #ddd;
}
/*end plugin css*/
JavaScript
/// By Konstantin Rouda https://il.linkedin.com/pub/konstantin-rouda/8a/2a9/262
; (function ($) {
'use strict';
var defaultOptions = {
wrapperClass: "custom-select-wrapper",
pointerClass: "pointer",
displayInputClass: "custom-select-display",
selectOptionsClass: "custom-select-options",
selectOptionClass: "custom-select-option",
selectOptionsOpenClass: "open",
selectOptionActiveClass: "active"
};
$.fn.customSelect = function (options) {
$.extend(defaultOptions, options);
return this.each(function (index, element) {
var $wrapper = $("<div />", { "class": defaultOptions.wrapperClass, "id": "custom-select-" + (index + 1) });
var $pointer = $("<span />", { "class": defaultOptions.pointerClass, "text": "â–Ľ" });
var $displayInput = $("<input />", { "class": defaultOptions.displayInputClass, "value": element.options[0].textContent, "type": "text", "readonly": true, "aria-invalid": false });
var $ul = $("<ul />", { "class": defaultOptions.selectOptionsClass, "tabindex": (100 + index) });
for (var i = 0, len = element.options.length; i < len; i++) {
var option = element.options[i];
var $li = $("<li />", { "class": defaultOptions.selectOptionClass, "text": option.textContent, "data-value": option.value });
if (option.selected) { $li.addClass("active"); $displayInput.val(option.textContent); };
$ul.append($li);
};
$ul.on("click", "." + defaultOptions.selectOptionClass, customSelectOnClick);
$ul.on("blur", wrapperCloseSelect);
$wrapper.on("click", wrapperOpenSelect);
$(element).parent().append($wrapper);
$wrapper.append($pointer).append($displayInput).append($ul).append(element);
});
};
function customSelectOnClick(e) {
var $self = $(this),
$parent =...