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 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>
@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);
}
//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");
}
}
});
Also see: Tab Triggers