HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<div id="wapper">
<h2>Custom Select Option</h2>
<ul class='info'>
<li>Custom html</li>
<li>Multiple color</li>
<li>Typing to search</li>
<li>Event change</li>
</ul>
<div class="style1">
<select class="select">
<option value="1">This is a test select option</option>
<option value="2">Hello World</option>
<option value="3">Click me!</option>
</select>
<select class="select">
<option value="0">Facebook</option>
<option value="2">Google</option>
<option value="3">Yahoo!</option>
<option value="4" selected="">Twitter</option>
<option value="5">Princess</option>
<option value="6">Youtube</option>
<option value="8">Instagram</option>
</select>
<select class="test">
<option value="0">Firefox</option>
<option value="2">Chrome</option>
<option value="3">Safari</option>
<option value="4">Internet Explorer</option>
</select>
</div>
<div id="event-change"></div>
</div>
<a href="https://codepen.io/HieuHuynh/pen/xbqRXe" target="_blank" class="custom-link">Product Animation <i class="fa fa-arrow-right"></i></a>
@import url(https://fonts.googleapis.com/css?family=Neucha);
@import url(https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css);
/*@import url(font-icomoon.css);*/
@import url(https://code.ionicframework.com/ionicons/2.0.0/css/ionicons.min.css);
@import url(https://fonts.googleapis.com/css?family=Oswald:400,300,700);
/** Custom field plugin **/
/* SELECT */
.selectCF{
margin:0;
padding:0;
display:inline-block;
position:relative;
font-family: 'Neucha', cursive;
font-size:17px;
font-weight:bold;
}
.selectCF li{
list-style:none;
cursor: pointer;
perspective: 900px;
-webkit-perspective: 900px;
text-align: left;
}
.selectCF > li{
position:relative;
font-size:0;
}
.selectCF span{
display:inline-block;
height:45px;
line-height:45px;
color:#FFF;
z-index:1;
}
.selectCF .arrowCF{
transition: .3s;
-webkit-transition: .3s;
width:45px;
text-align:center;
vertical-align: top;
font-size:17px;
}
.selectCF .titleCF{
padding: 0 10px 0 20px;
border-left: dotted 1px rgba(244,244,244,.5);
font-size:16px;
font-family: 'Oswald', sans-serif;
font-weight:400;
overflow:hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.selectCF .searchCF{
padding: 0 10px 0 20px;
border-left: dotted 1px rgba(244,244,244,.5);
position: absolute;
top:0;
right:0;
z-index:-1;
}
@keyframes searchActive {
from{ transform: rotateY(180deg) }
to{ transform: rotateY(0deg); }
}@-moz-keyframes searchActive {
from{ transform: rotateY(180deg) }
to{ transform: rotateY(0deg); }
}
@-webkit-keyframes searchActive {
from{ -webkit-transform: rotateY(180deg) }
to{ -webkit-transform: rotateY(0deg); }
}
.searchActive .searchCF{
z-index:1;
animation: searchActive 0.3s alternate 1;
-moz-animation: searchActive 0.3s alternate 1;
-webkit-animation: searchActive 0.3s alternate 1;
}
.searchActive .titleCF{
opacity:0;
}
.selectCF .searchCF input{
font-family: 'Neucha', cursive;
line-height:45px;
border:none;
padding:0;
margin:0;
width:100%;
height:100%;
background:transparent;
font-size:17px;
}
.selectCF .searchCF input:active, .selectCF .searchCF input:focus{
box-shadow:none;
border:none;
outline: none;
}
.selectCF li ul{
display:none;
position:absolute;
top:100%;
left:0;
padding: 0 !important;
width:100%;
background: #FFF;
max-height: 255px;
overflow-y: auto;
transition: .2s;
-webkit-transition: .2s;
z-index:2;
background:rgba(253,253,253,.9);
}
.selectCF li ul li{
padding:9px 0 9px 20px;
border-bottom: 1px solid rgba(240,240,240,.9);
font-weight:normal;
font-size:14px;
transition: .2s;
-webkit-transition: .2s;
overflow:hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.selectCF li ul li:hover{
background: #666;
color:#FFF;
}
.selectCF .selected{
background: #666;
color:#FFF;
}
.selectCF li ul li:last-child{
border-bottom: none;
}
.onCF .arrowCF{
transform: rotate(90deg);
-webkit-transform: rotate(90deg);
}
@-moz-keyframes effect1 {
from{ transform: translateY(15px); opacity:0; }
to{ transform: translateY(0px); opacity:1; }
}
@-webkit-keyframes effect1 {
from{ -webkit-transform: translateY(15px); opacity:0; }
to{ -webkit-transform: translateY(0px); opacity:1; }
}
.onCF li ul{
display:block;
-moz-animation: effect1 0.3s alternate 1;
-webkit-animation: effect1 0.3s alternate 1;
}
/**************************/
html{
background: url('https://unsplash.com/photos/zJnpPhF4HyY/download');
background-size: cover;
text-align: center
}
h2, ul.info li, #event-change{
font-family: 'Oswald', cursive;
color: #FFF;
}
ul.info{
padding: 0;
margin: 0 0 20px 0;
}
ul.info li{
display: inline-block;
border: solid 1px #FFF;
border-radius: 5px;
padding: 0 5px;
}
#event-change{
padding: 20px 0;
}
.custom-link{
position: absolute;
bottom: 30px;
right: 30px;
color: #FFF;
font-size: 12px;
text-decoration: none;
transition: .3s;
-webkit-transition: .3s;
font-family: 'Oswald', sans-serif;
font-size: 20px
}
a:hover{
color: #E4432C;
}
(function ( $ ) {
var elActive = '';
$.fn.selectCF = function( options ) {
// option
var settings = $.extend({
color: "#FFF", // color
backgroundColor: "#50C9AD", // background
change: function( ){ }, // event change
}, options );
return this.each(function(){
var selectParent = $(this);
list = [],
html = '';
//parameter CSS
var width = $(selectParent).width();
$(selectParent).hide();
if( $(selectParent).children('option').length == 0 ){ return; }
$(selectParent).children('option').each(function(){
if( $(this).is(':selected') ){ s = 1; title = $(this).text(); }else{ s = 0; }
list.push({
value: $(this).attr('value'),
text: $(this).text(),
selected: s,
})
})
// style
var style = " background: "+settings.backgroundColor+"; color: "+settings.color+" ";
html += "<ul class='selectCF'>";
html += "<li>";
html += "<span class='arrowCF ion-chevron-right' style='"+style+"'></span>";
html += "<span class='titleCF' style='"+style+"; width:"+width+"px'>"+title+"</span>";
html += "<span class='searchCF' style='"+style+"; width:"+width+"px'><input style='color:"+settings.color+"' /></span>";
html += "<ul>";
$.each(list, function(k, v){ s = (v.selected == 1)? "selected":"";
html += "<li value="+v.value+" class='"+s+"'>"+v.text+"</li>";})
html += "</ul>";
html += "</li>";
html += "</ul>";
$(selectParent).after(html);
var customSelect = $(this).next('ul.selectCF'); // add Html
var seachEl = $(this).next('ul.selectCF').children('li').children('.searchCF');
var seachElOption = $(this).next('ul.selectCF').children('li').children('ul').children('li');
var seachElInput = $(this).next('ul.selectCF').children('li').children('.searchCF').children('input');
// handle active select
$(customSelect).unbind('click').bind('click',function(e){
e.stopPropagation();
if($(this).hasClass('onCF')){
elActive = '';
$(this).removeClass('onCF');
$(this).removeClass('searchActive'); $(seachElInput).val('');
$(seachElOption).show();
}else{
if(elActive != ''){
$(elActive).removeClass('onCF');
$(elActive).removeClass('searchActive'); $(seachElInput).val('');
$(seachElOption).show();
}
elActive = $(this);
$(this).addClass('onCF');
$(seachEl).children('input').focus();
}
})
// handle choose option
var optionSelect = $(customSelect).children('li').children('ul').children('li');
$(optionSelect).bind('click', function(e){
var value = $(this).attr('value');
if( $(this).hasClass('selected') ){
//
}else{
$(optionSelect).removeClass('selected');
$(this).addClass('selected');
$(customSelect).children('li').children('.titleCF').html($(this).html());
$(selectParent).val(value);
settings.change.call(selectParent); // call event change
}
})
// handle search
$(seachEl).children('input').bind('keyup', function(e){
var value = $(this).val();
if( value ){
$(customSelect).addClass('searchActive');
$(seachElOption).each(function(){
if( $(this).text().search(new RegExp(value, "i")) < 0 ) {
// not item
$(this).fadeOut();
}else{
// have item
$(this).fadeIn();
}
})
}else{
$(customSelect).removeClass('searchActive');
$(seachElOption).fadeIn();
}
})
});
};
$(document).click(function(){
if(elActive != ''){
$(elActive).removeClass('onCF');
$(elActive).removeClass('searchActive');
}
})
}( jQuery ));
$(function(){
var event_change = $('#event-change');
$( ".select" ).selectCF({
change: function(){
var value = $(this).val();
var text = $(this).children('option:selected').html();
console.log(value+' : '+text);
event_change.html(value+' : '+text);
}
});
$( ".test" ).selectCF({
color: "#FFF",
backgroundColor: "#663052",
});
})
Also see: Tab Triggers