JSFiddle - React, Tailwind, and code Playground
HTML
<select>
<option>Название запчасти</option>
<option>Автопилот</option>
<option>Бардачек</option>
<option>Движок</option>
<option>Амортизатор</option>
<option>Датчик детонации</option>
</select>
CSS
*{
padding: 0;
margin: 0;
}
.selectbox {
vertical-align: middle;
cursor: pointer;
margin: 4px 0;
}
.selectbox .select {
width: 185px;
height: 30px;
line-height: 30px;
padding: 0 45px 0 10px;
font-size: 16px;
font-family: calibri, arial, verdana, tahoma;
color: #000;
background: #F0F0F0;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
}
.selectbox .select:hover {
background-color: #E6E6E6;
background-position: 0 -10px;
}
.selectbox .select:active {
background: #f5f5f5;
box-shadow: inset 0 1px 3px rgba(0,0,0,0.15);
}
.selectbox.focused .select {
border: 1px solid #5794BF;
}
.selectbox .select .text {
display: block;
width: 100%;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
.selectbox .trigger {
position: absolute; top: 0; right: 0;
width: 34px;
height: 100%;
}
.selectbox .trigger .arrow {
position: absolute; top: 14px; right: 12px;
border-left: 7px solid transparent;
border-right: 7px solid transparent;
border-top: 7px solid #000;
width: 0;
height: 0;
overflow: hidden;
opacity: 0.3;
filter: alpha(opacity=30);
}
.selectbox:hover .arrow {
opacity: 1;
filter: alpha(opacity=100);
}
.selectbox .dropdown {
top: 33px;
width: 240px;
margin: 0;
padding: 4px 0;
background: #FFF;
box-shadow: 0 2px 10px rgba(0,0,0,0.2);
font-size: 16px;
font-family: calibri, arial, verdana, tahoma;
color: #000;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
}
.selectbox li {
padding: 5px 10px 6px;
color: #231F20;
list-style: none;
}
.selectbox li.selected {
background: #ccc;
color: #FFF;
}
.selectbox li:hover {
background: #FF7700;
color: #FFF;
}
.selectbox li.disabled {
color: #AAA;
}
.selectbox li.disabled:hover {
background: none;
}
JavaScript
/* jQuery SelectBox Styler v1.0.1 | (c) Dimox | http://dimox.name/styling-select-boxes-using-jquery-css/ */
(function($){$.fn.selectbox=function(){$(this).each(function(){var select=$(this);if(select.prev('span.selectbox').length<1){function doSelect(){var option=select.find('option');var optionSelected=option.filter(':selected');var optionText=option.filter(':first').text();if(optionSelected.length)optionText=optionSelected.text();var ddlist='';for(i=0;i<option.length;i++){var selected='';var disabled=' class="disabled"';if(option.eq(i).is(':selected'))selected=' class="selected sel"';if(option.eq(i).is(':disabled'))selected=disabled;ddlist+='<li'+selected+'>'+option.eq(i).text()+'</li>';}var selectbox=$('<span class="selectbox" style="display:inline-block;position:relative">'+'<div class="select" style="float:left;position:relative;z-index:10000"><div class="text">'+optionText+'</div>'+'<b class="trigger"><i class="arrow"></i></b>'+'</div>'+'<div class="dropdown" style="position:absolute;z-index:9999;overflow:auto;overflow-x:hidden;list-style:none">'+'<ul>'+ddlist+'</ul>'+'</div>'+'</span>');select.before(selectbox).css({position:'absolute',top:-9999});var divSelect=selectbox.find('div.select');var divText=selectbox.find('div.text');var dropdown=selectbox.find('div.dropdown');var li=dropdown.find('li');var selectHeight=selectbox.outerHeight();if(dropdown.css('left')=='auto')dropdown.css({left:0});if(dropdown.css('top')=='auto')dropdown.css({top:selectHeight});var liHeight=li.outerHeight();var position=dropdown.css('top');dropdown.hide();divSelect.click(function(){var topOffset=selectbox.offset().top;var bottomOffset=$(window).height()-selectHeight-(topOffset-$(window).scrollTop());if(bottomOffset<0||bottomOffset<liHeight*6){dropdown.height('auto').css({top:'auto',bottom:position});if(dropdown.outerHeight()>topOffset-$(window).scrollTop()-20){dropdown.height(Math.floor((topOffset-$(window).scrollTop()-20)/liHeight)*liHeight);}}else...