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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
<header>
<!-- /.border-b -->
<div x-data="{ animate: false }" class="flex flex-col mx-auto max-w-screen lg:px-4 lg:items-center lg:justify-between lg:flex-row lg:px-6 lg:px-8">
<div class="container container-wide">
<div class="w-full flex-flex-row">
<div class="flex flex-row items-center justify-between px-4 lg:py-4">
<a href="/en/" class="text-lg font-semibold tracking-widest text-gray-900 uppercase rounded-lg dark-mode:text-white focus:outline-none focus:shadow-outline">
</a>
<button class="p-2 my-4 -mr-4 border rounded-lg md:hidden focus:outline-none focus:shadow-outline border-borderColor" @click.prevent="animate = (animate) ? false : true;document.body.classList.add('overflow-hidden');">
<span class="sr-only">Toggle Navigation</span>
<svg viewBox="0 0 100 80" width="40" height="40">
<rect width="100" height="10"></rect>
<rect y="30" width="100" height="10"></rect>
<rect y="60" width="100" height="10"></rect>
</svg>
</button>
</div>
<nav
aria-label="primary"
class="relative z-20 flex-col flex-grow hidden w-full pb-4 md:pb-0 md:flex md:justify-between md:flex-row">
<div class="relative flex flex-col group">
<a href="#" class="flex-row items-center block w-full px-4 py-4 mt-2 text-base font-bold text-left uppercase bg-transparent rounded-lg md:w-auto md:inline md:mt-0 md:ml-4 focus:outline-none font-montserrat text-textBrand-nav">
<span class="inline-block">Services</span>
</a>
<div class="absolute z-10 flex-col hidden bg-grayBrand-dropdown group-hover:block w-560 mt-nav">
<div class="flex flex-row w-full">
<div class="w-3/5 p-4 bg-white shadow-lg">
<div class="flex flex-col mx-3">
<a href="#" class="flex flex-row block pb-2 mb-4 no-underline border-b hover:underline text-textBrand-nav text-14 font-robotoCondensed hover:font-bold border-grayBrand-light">
Lorem Link
</a>
<a href="#" class="flex flex-row block pb-2 mb-4 no-underline border-b hover:underline text-textBrand-nav text-14 font-robotoCondensed hover:font-bold border-grayBrand-light">
Lorem Link
</a>
<a href="#" class="flex flex-row block pb-2 mb-4 no-underline border-b hover:underline text-textBrand-nav text-14 font-robotoCondensed hover:font-bold border-grayBrand-light">
Lorem Link
</a>
<a href="#" class="flex flex-row block pb-2 mb-4 no-underline border-b hover:underline text-textBrand-nav text-14 font-robotoCondensed hover:font-bold border-grayBrand-light">
Lorem Link
</a>
</div>
</div>
<div class="w-2/5 p-4">
<p class="font-bold uppercase text-14 text-textBrand">Featured Links</p>
<ul>
<li><a href="#" target="_self">Lorem Link</a></li>
<li><a href="#" target="_self">Lorem Link</a></li>
<li><a href="#" target="_self">Lorem Link</a></li>
<li><a href="#" target="_self">Lorem Link</a></li>
</ul>
<!-- /.testing -->
</div>
</div>
<!-- /.flex flex-row w-full -->
</div>
</div>
<div class="relative flex flex-col group">
<a href="#" class="flex-row items-center block w-full px-4 py-4 mt-2 text-base font-bold text-left uppercase bg-transparent rounded-lg md:w-auto md:inline md:mt-0 md:ml-4 focus:outline-none font-montserrat text-textBrand-nav">
<span class="inline-block">Opportunities</span>
</a>
<div class="absolute z-10 hidden mt-nav bg-grayBrand-dropdown w-280 group-hover:block">
<div class="px-2 pt-2 pb-4 shadow-lg">
<div class="flex flex-col mx-3">
<a href="#" class="flex flex-row block pb-2 mb-4 no-underline border-b hover:underline text-textBrand-nav text-14 font-robotoCondensed hover:font-bold border-grayBrand-light">
Lorem Link
</a>
<a href="#" class="flex flex-row block pb-2 mb-4 no-underline border-b hover:underline text-textBrand-nav text-14 font-robotoCondensed hover:font-bold border-grayBrand-light">
Lorem Link
</a>
<a href="#" class="flex flex-row block pb-2 mb-4 no-underline border-b hover:underline text-textBrand-nav text-14 font-robotoCondensed hover:font-bold border-grayBrand-light">
Lorem Link
</a>
</div>
</div>
</div>
</div>
<div class="relative group">
<button class="flex flex-row items-center w-full px-4 py-4 mt-2 text-base font-bold text-left uppercase bg-transparent rounded-lg md:w-auto md:inline md:mt-0 md:ml-4 focus:outline-none font-montserrat">
<span>Projects</span>
</button>
<div class="absolute z-10 hidden bg-grayBrand-dropdown w-280 group-hover:block">
<div class="px-2 pt-2 pb-4 shadow-lg">
<div class="flex flex-col mx-3">
<a href="#" class="flex flex-row block pb-2 mb-4 no-underline border-b hover:underline text-textBrand-nav text-14 font-robotoCondensed hover:font-bold border-grayBrand-light">
Lorem Link
</a>
<a href="#" class="flex flex-row block pb-2 mb-4 no-underline border-b hover:underline text-textBrand-nav text-14 font-robotoCondensed hover:font-bold border-grayBrand-light">
Lorem Link
</a>
</div>
</div>
</div>
</div>
<div class="relative flex flex-col group">
<a href="https://hotd-craft.clients.bostonwebdevelopment.com/accelerators/" class="flex-row items-center block w-full px-4 py-4 mt-2 text-base font-bold text-left uppercase bg-transparent rounded-lg md:w-auto md:inline md:mt-0 md:ml-4 focus:outline-none font-montserrat text-textBrand-nav">
<span class="inline-block">Projects</span>
</a>
<div class="absolute z-10 hidden mt-nav bg-grayBrand-dropdown w-280 group-hover:block">
<div class="px-2 pt-2 pb-4 shadow-lg">
<div class="flex flex-col mx-3">
<a href="#" class="flex flex-row block pb-2 mb-4 no-underline border-b hover:underline text-textBrand-nav text-14 font-robotoCondensed hover:font-bold border-grayBrand-light">
Lorem Link
</a>
<a href="#" class="flex flex-row block pb-2 mb-4 no-underline border-b hover:underline text-textBrand-nav text-14 font-robotoCondensed hover:font-bold border-grayBrand-light">
Lorem Link
</a>
<a href="#" class="flex flex-row block pb-2 mb-4 no-underline border-b hover:underline text-textBrand-nav text-14 font-robotoCondensed hover:font-bold border-grayBrand-light">
Lorem Link
</a>
</div>
</div>
</div>
</div>
<div class="relative flex flex-col group">
<a href="#" class="flex-row items-center block w-full px-6 py-4 mt-2 text-base font-bold text-left uppercase bg-transparent rounded-lg md:w-auto md:inline md:mt-0 md:ml-4 focus:outline-none font-montserrat text-textBrand-nav">
<span class="inline-block">About Us</span>
</a>
<div class="absolute z-10 hidden mt-nav bg-grayBrand-dropdown w-280 group-hover:block">
<div class="px-2 pt-2 pb-4 shadow-lg">
<div class="flex flex-col mx-3">
<a href="#" class="flex flex-row block pb-2 mb-4 no-underline border-b hover:underline text-textBrand-nav text-14 font-robotoCondensed hover:font-bold border-grayBrand-light">
Lorem Link
</a>
<a href="#" class="flex flex-row block pb-2 mb-4 no-underline border-b hover:underline text-textBrand-nav text-14 font-robotoCondensed hover:font-bold border-grayBrand-light">
Lorem Link
</a>
<a href="#" class="flex flex-row block pb-2 mb-4 no-underline border-b hover:underline text-textBrand-nav text-14 font-robotoCondensed hover:font-bold border-grayBrand-light">
Lorem Link
</a>
<a href="#" class="flex flex-row block pb-2 mb-4 no-underline border-b hover:underline text-textBrand-nav text-14 font-robotoCondensed hover:font-bold border-grayBrand-light">
Lorem Link
</a>
<a href="#" class="flex flex-row block pb-2 mb-4 no-underline border-b hover:underline text-textBrand-nav text-14 font-robotoCondensed hover:font-bold border-grayBrand-light">
Lorem Link
</a>
</div>
</div>
</div>
</div>
</nav>
</div>
<!-- /.flex-flex-row w-full -->
</div>
<!-- /.container container-wide -->
<nav
class="absolute top-0 right-0 z-50 w-2/3 h-full min-h-screen py-6 pl-4 pr-16 overflow-x-visible overflow-y-scroll border-l border-gray-800 bg-blue-600"
:class="{ 'hidden': false }"
x-show="animate"
@click.away="animate = false"
x-transition:enter="transition ease-out duration-200 origin-right"
x-transition:enter-start="transform scale-x-0 opacity-0"
x-transition:enter-end=" transform scale-x-100 opacity-100"
x-transition:leave="transition ease-in duration-200 origin-right"
x-transition:leave-start=" transform scale-x-100 opacity-100"
x-transition:leave-end=" transform scale-x-0 opacity-0"
x-cloak>
<button @click.prevent="animate = (animate) ? false : true;document.body.classList.remove('overflow-hidden');" class="relative px-2 py-1 mb-8 text-white">X</button>
<ul>
<li class="uppercase font-robotoCondensed text-15">
<a href="#" class="block py-2 text-white no-underline border-b border-white">Contact Us</a>
</li>
<li class="mt-2 uppercase font-robotoCondensed text-15">
<a href="#" class="block py-2 text-white no-underline border-b border-white">Services</a>
<ul class="pl-3 mt-4 list-inside">
<li class="my-2 font-robotoCondensed"><a href="#" class="py-6 text-white no-underline normal-case text-13">Lorem Link</a></li>
<li class="my-2 font-robotoCondensed"><a href="#" class="py-6 text-white no-underline normal-case text-13">Lorem Link</a></li>
<li class="my-2 font-robotoCondensed"><a href="#" class="py-6 text-white no-underline normal-case text-13">Lorem Link</a></li>
<li class="my-2 font-robotoCondensed"><a href="#" class="py-6 text-white no-underline normal-case text-13">Lorem Link</a></li>
</ul>
</li>
<li class="mt-2 uppercase font-robotoCondensed text-15">
<a href="#" class="block py-2 text-white no-underline border-b border-white">Opportunities</a>
<ul class="pl-3 mt-4 list-inside">
<li class="my-2 font-robotoCondensed"><a href="#" class="py-6 text-white no-underline normal-case text-13">Lorem Link</a></li>
<li class="my-2 font-robotoCondensed"><a href="#" class="py-6 text-white no-underline normal-case text-13">Lorem Link</a></li>
</ul>
</li>
<li class="mt-2 uppercase font-robotoCondensed text-15">
<a href="https://hotd-craft.clients.bostonwebdevelopment.com/accelerators/" class="block py-2 text-white no-underline border-b border-white">Projects</a>
<ul class="pl-3 mt-4 list-inside">
<li class="my-2 font-robotoCondensed"><a href="#" class="py-6 text-white no-underline normal-case text-13">Lorem Link</a></li>
<li class="my-2 font-robotoCondensed"><a href="#" class="py-6 text-white no-underline normal-case text-13">Lorem Link</a></li>
<li class="my-2 font-robotoCondensed"><a href="#" class="py-6 text-white no-underline normal-case text-13">Lorem Link</a></li>
</ul>
</li>
<li class="mt-2 uppercase font-robotoCondensed text-15">
<a href="#" class="block py-2 text-white no-underline border-b border-white">About Us</a>
<ul class="pl-3 mt-4 list-inside">
<li class="my-2 font-robotoCondensed"><a href="#" class="py-6 text-white no-underline normal-case text-13">Lorem Link</a></li>
<li class="my-2 font-robotoCondensed"><a href="#" class="py-6 text-white no-underline normal-case text-13">Lorem Link</a></li>
<li class="my-2 font-robotoCondensed"><a href="#" class="py-6 text-white no-underline normal-case text-13">Lorem Link</a></li>
<li class="my-2 font-robotoCondensed"><a href="#" class="py-6 text-white no-underline normal-case text-13">Lorem Link</a></li>
<li class="my-2 font-robotoCondensed"><a href="#" class="py-6 text-white no-underline normal-case text-13">Lorem Link</a></li>
</ul>
</li>
<li class="uppercase font-robotoCondensed text-15">
<a href="#" class="block py-2 text-white no-underline border-b border-white">News</a>
</li>
<li class="uppercase font-robotoCondensed text-15">
<a href="#" class="block py-2 text-white no-underline border-b border-white">Events</a>
</li>
</ul>
</nav>
<div>
</header>
<main>
<div class="container p-4 bg-blue-200 mb-8">
<h1 class="text-3xl mb-8 leading-snug">Dropdown Nav with mobile off-canvas menu using Tailwind and AlpineJs</h1>
<p class="text-lg mb-4">
Dropdowns not working in <span class="font-bold">codepen</span> because the CDN version of tailwind does not <a href="https://tailwindcss.com/docs/pseudo-class-variants#group-hover">include group:hover</a>.
Add the following to your tailwind config file and the hover dropdowns will work.
</p>
<code class="font-monospace bg-gray-100 p-2 my-8 block">
display: ['responsive', 'group-hover', 'group-focus'],
</code>
<p class="text-lg mb-4">
I recieved some assistance from the AlpineJs discord community setting up the offcanvas for another project, but have adapted it to work here for the mobile menu.
</p>
</div>
<div class="container p-4 bg-gray-200">
<p class="text-lg mb-4">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Magni commodi necessitatibus itaque assumenda rerum? Sunt enim maxime nesciunt fugiat odit aspernatur veniam fuga harum, sint quisquam in! Suscipit, laboriosam. Repellat inventore corporis tempore nesciunt nobis fugiat autem magnam totam quo.
</p><!-- /.text-lg mb-4 -->
<p class="text-lg mb-4">
Accusantium modi amet aliquid at quas labore voluptate similique nisi veniam beatae, consectetur ex blanditiis cum, minus fugiat aliquam libero corporis officia ratione? Ipsum nulla totam doloremque repudiandae veniam iste vel illo corporis? Inventore sapiente officia, eos maxime consequatur id!
</p><!-- /.text-lg mb-4 -->
<p class="text-lg mb-4">
Ut fugiat, soluta sint dolorem possimus nihil et excepturi in odio eaque voluptatum ipsam itaque, delectus recusandae. Laboriosam atque tempore sint unde tempora cumque harum? Maxime, repellendus nobis molestias aspernatur quo, optio aperiam tempora possimus quis illo a impedit minima!
</p><!-- /.text-lg mb-4 -->
<p class="text-lg mb-4">
Ipsa maxime, eligendi repellat cumque exercitationem asperiores eos enim debitis unde distinctio accusamus consequatur. Impedit vero error nostrum at. Possimus commodi maxime magnam laboriosam earum, sed error tempora molestias laudantium asperiores delectus cupiditate esse minus odit eum illo voluptatem quam.
</p><!-- /.text-lg mb-4 -->
<p class="text-lg mb-4">
Accusantium explicabo consequuntur eum nobis cum delectus eius numquam corrupti temporibus adipisci, perspiciatis repellat eligendi earum dignissimos minus ipsum labore odio possimus magnam molestiae ducimus animi. Quia, animi. Neque rerum eos nihil officia ipsum dolorum accusamus dignissimos laudantium earum aliquam.
</p><!-- /.text-lg mb-4 -->
<p class="text-lg mb-4">
Deleniti facilis quidem vitae, illum modi aperiam, officia earum optio at excepturi ad, perspiciatis tempore saepe non rem eos neque aliquid facere omnis dignissimos corporis vel nesciunt! Cupiditate velit assumenda aliquam nesciunt nemo asperiores dolore dignissimos, eveniet autem at eaque.
</p><!-- /.text-lg mb-4 -->
<p class="text-lg mb-4">
Et amet, reiciendis aliquid magni aperiam dicta molestias exercitationem, aspernatur corrupti earum sapiente? Iusto officia porro ratione sequi quo, magnam ea blanditiis quisquam fugit et maiores non vero dolorem, aspernatur omnis esse nemo error. Minus tempora beatae aperiam vel dicta.
</p><!-- /.text-lg mb-4 -->
</div>
</main>
[x-cloak] {
display: none;
}
Also see: Tab Triggers