Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

Save Automatically?

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 id="content">
		<div id='popup_content'>
			<h1>Custom select</h1>
			<fieldset>
				<legend>Simple Select</legend>
				<form id="form_language">
				<label for="language">My favorite language</label>
				<div class="select" >
					<div class='select_input' id="id_select_input" >
						<input type="text" id="language" name="language" readonly="readonly" class='select_text' placeholder="Select a language"/>
						<div class='select_icon'>
							<span class='caret'></span>
						</div>
					</div>
					<div class='select_box'>
						<div class='select_item' data-valeur="JavaScript">
							JavaScript
						</div>
						<div class='select_item'data-valeur="PHP">
							PHP
						</div>
						<div class='select_item' data-valeur="CSS">
							CSS
						</div>
						<div class='select_item' data-valeur="HTML">
							HTML
						</div>
						<div class='select_item' data-valeur="Python">
							Python
						</div>
						<div class='select_item' data-valeur="Ruby">
							Ruby
						</div>
						<div class='select_item' data-valeur="C#">
							C#
						</div>
						<div class='select_item' data-valeur="Java">
							Java
						</div>
						<div class='select_item' data-valeur="C/C++">
							C/C++
						</div>
						<div class='select_item' data-valeur="Bash">
							Bash
						</div>
					</div>
				</div>
				<input type="button" value="Display">
				</form>
			</fieldset>
			<fieldset>
			<legend>Select with clickable optgroup</legend>
				<form id="form_framework">
				<label for="language">My favorite Framework</label>
				<div class="select" >
					<div class='select_input' >
						<input type="text" id="framework" name="framework" readonly="readonly" class='select_text' placeholder="Select a framework"/>
						<div class='select_icon'>
							<span class='caret'></span>
						</div>
					</div>
					<div class='select_box'>
						<div class='select_group'>
							<div class='select_header'>
								PHP
								<div class='select_icon'>
									<span class='caret'></span>
								</div>
							</div>
							<div class='select_item' data-valeur="Symfony">
								Symfony
							</div>
							<div class='select_item' data-valeur="CakePHP">
								CakePHP
							</div>
							<div class='select_item' data-valeur="Laravel">
								Laravel
							</div>
							<div class='select_item' data-valeur="Zend Framework">
								Zend Framework
							</div>
							<div class='select_item' data-valeur="CodeIgniter">
								CodeIgniter
							</div>
						</div>
						<div class='select_group'>
							<div class='select_header'>
								JavaScript
								<div class='select_icon'>
									<span class='caret'></span>
								</div>
							</div>
							<div class='select_item' data-valeur="JQuery">
								JQuery
							</div>
							<div class='select_item' data-valeur="AngularJS">
								AngularJS
							</div>
							<div class='select_item' data-valeur="VanillaJS">
								VanillaJS
							</div>
							<div class='select_item'data-valeur="React">
								React
							</div>
						</div>

						<div class='select_group'>
							<div class='select_header'>
								Python
								<div class='select_icon'>
									<span class='caret'></span>
								</div>
							</div>
							<div class='select_item' data-valeur="Django">
								Django
							</div>
							<div class='select_item' data-valeur="Pyramid">
								Pyramid
							</div>
							<div class='select_item' data-valeur="TurboGears">
								TurboGears
							</div>
							
						</div>
					
						<div class='select_group'>
							<div class='select_header'>
								CSS
								<div class='select_icon'>
									<span class='caret'></span>
								</div>
							</div>
							<div class='select_item' data-valeur="Bootstrap">
								Bootstrap
							</div>
							<div class='select_item' data-valeur="Zurb Fundation">
								Zurb Fundation
							</div>
							<div class='select_item' data-valeur="Bulma">
								Bulma
							</div>
						</div>
						
					</div>
				</div>
				<input type="button" value="Display">
		</form>
		</fieldset>
		
		</div>
	</div>
		<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
              
            
!

CSS

              
                /**
 * Custom select file style
 * @author Alicia Malacarne
 * 2017-2019
 * */
body{
	font-family:arial;
	font-size:18px;
}
 #content{
 	width:70%;
 	margin:0 auto;
 }
 fieldset{
 	margin:4% auto;
 	width:50%;
 	border-radius: 5px;
 	box-shadow: 1px 2px 2px 2px #696969;
 	border:none;
 	text-align: center;
 }
 legend{
 	padding: 0 5px;
 	font-weight: bold;
 	font-size:20px;
 	background-color: #fff;
 }
label, .select, input[type="button"] {
	max-width: 90%;
	margin: 3%;
}
.select .select_box {
	display: none;
	flex-direction: column;
	flex-wrap: nowrap;
	z-index: 99999;
	margin-top:0;
	position: absolute;
	border: 1px solid #1E90FF;
	box-shadow:2px 2px 2px #696969;
	
	overflow-x: hidden;
	overflow-y: visible;
}
.select .select_input {
	display: flex;
	flex-wrap:nowrap;
	width:100%;
	padding:0;
}

.select_input, input[type="button"]{
	height:44px;
	background-color: #D3D3D3;
	border: 1px solid #7F7F7F;
}

.select_icon{
	width:9%;
	min-width: 7px;
	display:flex;
	justify-content: center;
	align-items:center; 
	height:100%;
	text-align:center;
}
/*down arrow*/
.caret{
	border-top:7px solid #111111;
	border-left:7px solid transparent;
	border-right:7px solid transparent;
	border-bottom:7px solid transparent;
	display:inline-block;
}
.remove::after{
	content:"x";
	font-family: verdana;
	font-weight:bold;
	font-size:20px;
	color: #111111;
}

.select_item, .select_header {
	display:flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap:nowrap;
 	width: 99%;
	height:44px;
	height:2.75em;
	padding: 0;
	padding-left: 1%;
	text-align: left;
}
.select_input *, input[type="button"], .select_header, .select_item {
	cursor: pointer;
}
.select_text {
	width: 90%;
	font-size:16px;
	text-align: left;
	flex:3;
	padding: 0;
	padding-left: 5px;
	border:none;
}
.select_input .select_text {
	color: #C0C0C0;
	background-color: #fff;
	height: 100%;
}

.select .select_box .select_group {
	width: 100%;
}
.select_item {
	background-color: #fff;
}
.select_group .select_item {
	display:none;
}
.select_header {
	background-color: #E5E8E8;
	border-bottom: 1px solid #ABB2B9;
	z-index:1000;
	font-weight: bold;
}

.select_item:nth-child(odd) {
	background-color: #DCDCDC;
}

.select_header:hover, .select_header[data-sslist='show'] {
	background-color: #7b76ab;
}
.select_item:hover{
	background-color:#B0C4DE;
}
/*fond invisible pour fermer la liste*/
#fade_transparant{
	display: none; /*--masqué par défaut--*/
	position: fixed; left: 0; top: 0;
	width: 100%; height: 100%;
	opacity: .0;
	z-index: 999;
}
/*bug IE6*/
*html #fade_transparant {
position: absolute;
}
*html .select {
position: absolute;
}


@media screen and (max-width:1024px){
	#content{
		width:100%;
	}
	.select_text{
		overflow: hidden;
	}
}
/*adapter les styles des ecrans tablettes et petits ordi*/
@media screen and (min-width:768px) and (max-width:979px){
	.select_text, .select_box .select_item, .select_header {
		font-size: 16px;
	}
	.select_input, .select_box .select_item, .select_header {
		height:40px;
		height:2.5rem;
	}
}
	
/*style ecrans smartphones et petites tabletts*/
@media screen and (max-width:767px){
	fieldset{
		width:70%;
	}
	.select_text, .select_box .select_item, .select_header {
		font-size: 14px;
	}
	.select_input, .select_item, .select_header {
		height:36px;
		height:2.25rem;
	}
}
/*smartphones*/
@media screen and (max-width:480px){
	fieldset{
		width:90%;
	}
	.select_box{
		max-height:90%;
		max-width:90%;
		margin-top:4% auto;
	}
	
}

@media screen and (max-width: 320px) {
	.select .remove {
		padding: 3px;
	}
}


              
            
!

JS

              
                /**
 * @author Alicia Malacarne
 * 2017-2019
 * Script coded with JQuery framework, take care to call it in your HTML pages
 * this function displays a boxlist when the .select_input field is clicked
 * Call select() function in your main JQuery script
 */
$(document).ready(function () {
  select();
  //button click
  $('[type=\'button\']').click(function () {
    var form = $(this).parent();
    var datas = form.serialize();
    var txt = 'My favorite ' + datas;
    alert(txt);
  });
});
function select() {
  //display the list
  $('.select .select_input').click(function () {
    var width = $(this).width();
    var box = $(this).parent().find('.select_box');
    box.css('display', 'flex').css('width', width + 'px');
    resize_boxlist(box);
    $('#popup_content').append('<div id=\'fade_transparant\'></div>');
    $('#fade_transparant').css({
      'filter': 'alpha(opacity=80)'
    }).fadeIn();
  });
  //close list
  $('#popup_content').on('click', '#fade_transparant', function () {
    close_select();
  });
  //display sub list
  $('.select_box .select_group .select_header').click(function () {
    //hide main items list
    $('.select_group .select_item').css('display', 'none');
    if ($(this).attr('data-sslist') == 'show') {
      //remove color selection and close icon
      $(this).removeAttr('data-sslist').find('.remove').removeClass('remove').addClass('caret');
      //display last header
      $('.select_header').css('display', 'flex');
    } else {
      //remove data-sslist attribute from all headers for getting just one
      $('.select_header[data-sslist=\'show\']').removeAttr('data-sslist').find('.remove').removeClass('remove').addClass('caret');
      $(this).attr('data-sslist', 'show').find('.caret').removeClass('caret').addClass('remove');
      $(this).parent().find('.select_item').css('display', 'flex');
      //hide others headers
      $('.select_header:not([data-sslist="show"]').css('display', 'none');
    }
    var box = $(this).parents('.select_box');
    resize_boxlist(box);
  });
  //change dropinput when click on item_list
  $('.select_item').click(function () {
    var val = $(this).attr('data-valeur');
    //modify text display on select_input
    $(this).parents('.select').find('.select_input .select_text').val(val);
    //close list and fade
    close_select();
  });
} 

/**
 * close list and field
 */
function close_select() {
  //hide select_box on item click
  $('.select_box').css({
    'display': 'none',
    'top': '',
    'max_height': ''
  });
  //reset display list parameters
  $('.select_box').find('.select_header').css('display', 'flex');
  $('.select_group').find('.select_item').css('display', 'none');
  $('.select_header[data-sslist=\'show\']').removeAttr('data-sslist').find('.remove').removeClass('remove').addClass('caret');
  $('#fade_transparant').fadeOut();
  $('#fade_transparant').remove();
}

/**
 * resize boxlist according to its size and window size
 */
function resize_boxlist(box) {
  var boxSize = 0;
  var groups=box.find('.select_group');
  var nb = groups.length;
  if(nb>0){
    for (var i = 0; i < nb; i++) {
      var elem=$(groups[i]);
      boxSize = boxSize + elem.height();
    }
  }
  //check boxlist position
  var H = $(window).height();
  var h = (boxSize == 0) ? box.height()  : boxSize;
  var t = box.offset().top;
  var T = box.prev().offset().top;
  if (h < H) {
    if ((h + t) > H) {
      if (h < T) {
        t = T - h;
      } else {
        t = (H - h) / 2;
      }
    }else{
      if(t<T){
        t=T-h;
      }
    }
  } else {
    h = H;
    t = 0;
    box.css('overflow-y', 'scroll');
  }
  box.css({
    'top': t + 'px',
    'max-height': h + 'px'
  });
}

              
            
!
999px

Console