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.
<!-- Include CDN JavaScript -->
<script src="https://unpkg.com/tailwindcss-jit-cdn"></script>
<script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.8.2/dist/alpine.min.js" defer></script>
<header>
<a href="#main-content" role="button" aria-label="Skip to main content" class="flex flex-col justify-center skip-main" style="height:40px;">Skip to main content</a><!-- /.skip-main -->
<!-- >>> TEMPLATE BEGIN >>> _includes/main-nav -->
<nav class="bg-white border-b border-gray-200">
<div class="w-full text-gray-700 max-w-screen container">
<div x-data="{ open: false }" class="flex flex-col mx-auto ax-w-screen lg:flex-row">
<div class="flex flex-row items-center justify-between px-4 py-2">
<a href="/" class="text-lg font-semibold tracking-widest text-gray-900 uppercase dark-mode:text-white focus:outline-none focus:shadow-outline">
insert logo
<span class="sr-only">Home</span>
</a>
<button class="mr-8 rounded-lg md:mr-12 lg:hidden focus:outline-none focus:shadow-outline" @click="open = !open">
<svg class="h-6 w-6" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512.001 512.001" x-show="open" style="display: none;"><path d="M284.286 256.002L506.143 34.144c7.811-7.811 7.811-20.475 0-28.285-7.811-7.81-20.475-7.811-28.285 0L256 227.717 34.143 5.859c-7.811-7.811-20.475-7.811-28.285 0-7.81 7.811-7.811 20.475 0 28.285l221.857 221.857L5.858 477.859c-7.811 7.811-7.811 20.475 0 28.285a19.938 19.938 0 0014.143 5.857 19.94 19.94 0 0014.143-5.857L256 284.287l221.857 221.857c3.905 3.905 9.024 5.857 14.143 5.857s10.237-1.952 14.143-5.857c7.811-7.811 7.811-20.475 0-28.285L284.286 256.002z"></path></svg>
<span class="sr-only" x-show="open" style="display: none;">Close Menu</span><!-- /.sr-only -->
<svg class="h-6 w-6" width="40" height="40" viewBox="0 0 100 80" x-show="!open"><path d="M0 0h100v10H0zm0 30h100v10H0zm0 30h100v10H0z"></path></svg>
<span class="sr-only" x-show="!open">Open Menu</span><!-- /.sr-only -->
</button>
</div>
<nav class="flex-col flex-grow hidden h-screen pb-4 lg:pb-0 lg:flex lg:justify-start lg:flex-row lg:h-auto" aria-label="Main Navigation" :class="{'flex': open, 'hidden': !open}">
<ul class="flex flex-col flex-wrap pl-0 m-0 lg:flex-row">
<li class="group relative
block lg:px-0 xl:px-0 mr-1 py-2" x-data="{isOpen:false }" @mouseleave="isOpen = false">
<a href="#" class="py-2
px-4 group-hover:bg-gray-400 group-hover:text-white" @click="isOpen = !isOpen" x-on:click.prevent="" :class="{'' : isOpen}">
About
<svg xmlns="http://www.w3.org/2000/svg" fill="#000" width="16" height="16" class="hidden lg:inline-block relative top-0 right-0 transform rotate-90" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z"></path>
</svg>
</a>
<ul class="bg-gray-600 p-2" aria-label="submenu" x-show="isOpen" @click.away="isOpen = false" style="display: none;">
<li class="group relative border-b border-white border-opacity-[0.2]">
<a href="https://craft-starter.ddev.site/pages/about/" class="py-2 text-white bg-transparent hover:text-gray-100 lg:text-sm">About</a>
</li><!-- /.p-3 bg-green-200 -->
<li class="group relative
border-b border-white border-opacity-[0.2]">
<a href="https://craft-starter.ddev.site/pages/about-2/" class="py-2
text-white bg-transparent hover:text-gray-100 lg:text-sm">
Sub Page
</a>
</li>
<li class="group relative
border-b border-white border-opacity-[0.2]" x-data="{isOpen:false }" @mouseleave="isOpen = false">
<a href="#" class="py-2
text-white bg-transparent hover:text-gray-100 lg:text-sm" @click="isOpen = !isOpen" x-on:click.prevent="" :class="{'' : isOpen}">
Sub Page 2
</a>
<svg xmlns="http://www.w3.org/2000/svg" fill="white" width="16" height="16" class="hidden lg:inline-block fill-white absolute top-[10px] right-0" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z"></path>
</svg>
<ul class="bg-gray-600 p-2" aria-label="submenu" x-show="isOpen" @click.away="isOpen = false" style="display: none;">
<li class="group relative border-b border-white border-opacity-[0.2]">
<a href="https://craft-starter.ddev.site/pages/about-2-2/" class="py-2 text-white bg-transparent hover:text-gray-100 lg:text-sm">Sub Page 2</a>
</li><!-- /.p-3 bg-green-200 -->
<li class="group relative
border-b border-white border-opacity-[0.2]">
<a href="https://craft-starter.ddev.site/pages/sub-sub-page/" class="py-2
text-white bg-transparent hover:text-gray-100 lg:text-sm">
Sub Sub Page
</a>
</li>
</ul>
</li>
<li class="group relative
border-b border-white border-opacity-[0.2]">
<a href="https://craft-starter.ddev.site/pages/about-2-2-2/" class="py-2
text-white bg-transparent hover:text-gray-100 lg:text-sm">
Sub Page 3
</a>
</li>
</ul>
</li>
<li class="group relative
block lg:px-0 xl:px-0 mr-1 py-2">
<a href="https://craft-starter.ddev.site/pages/services/" class="py-2
px-4 group-hover:bg-gray-400 group-hover:text-white">
Services
</a>
</li>
<li class="group relative
block lg:px-0 xl:px-0 mr-1 py-2">
<a href="https://craft-starter.ddev.site/pages/blog/" class="py-2
px-4 group-hover:bg-gray-400 group-hover:text-white">
Blog
</a>
</li>
</ul>
</nav>
</div>
</div>
</nav>
<!-- 18.95ms <<< TEMPLATE END <<< _includes/main-nav -->
</header>
<main id="main" class="my-8 px-4">
<h1 class="text-2xl">Accessible Dropdown Navigation with Tailwind CSS and Alpine Js</h1>
<div class="bg-yellow-200 p-8 my-8 max-w-lg">
<p class="text-xl">
The css tab on this codepen contains css from app.css that is compiled by laravel mix.</p>
<p class="text-xl"> See <a href="https://caffeinecreations.ca/blog/accessible-dropdown-navigation-with-tailwind-css-and-alpine-js/" class="underline hover:no-underline text-blue-500">blog post</a> for that css:
</p>
</div>
</main>
a.skip-main {
position: absolute;
top: 40px;
height: 1px;
width: 1px;
overflow: hidden;
left: -999px;
z-index: -999;
background: #2d2828;
}
a.skip-main:focus, a.skip-main:active {
left: 5px;
top: 50px;
z-index: 999;
margin-top: 10px;
margin-bottom: 10px;
margin-left: 5px;
margin-right: 5px;
min-width: 200px;
border-width: 1px;
--tw-border-opacity: 1;
border-color: rgba(0, 0, 0, var(--tw-border-opacity));
--tw-bg-opacity: 1;
background-color: rgba(45, 40, 40, var(--tw-bg-opacity));
padding: 10px;
text-align: center;
font-size: 1rem;
line-height: 1.5rem;
--tw-text-opacity: 1;
color: rgba(255, 255, 255, var(--tw-text-opacity));
text-decoration: none;
}
/* Nav */
nav li {
-webkit-transition-duration: 0.5s;
transition-duration: 0.5s;
}
nav li:hover, nav li:focus-within {
cursor: pointer;
}
nav ul li ul {
width: 100%;
--tw-bg-opacity: 1;
background-color: rgba(255, 255, 255, var(--tw-bg-opacity));
--tw-bg-opacity: 1;
background-color: rgba(156, 163, 175, var(--tw-bg-opacity));
padding-left: 0px;
padding-right: 0px;
padding-top: 0.25rem;
padding-bottom: 0.25rem;
padding-left: 2rem;
}
@media (min-width: 1024px) {
nav ul li ul {
position: absolute;
}
nav ul li ul {
left: 0px;
}
nav ul li ul {
width: 180px;
}
nav ul li ul {
min-width: 180px;
}
nav ul li ul {
max-width: 180px;
}
nav ul li ul {
padding-left: 0px;
}
nav ul li ul {
--tw-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
-webkit-box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
}
}
nav ul li ul {
z-index:9999;
-webkit-transition: all 0.5s ease;
transition: all 0.5s ease;
right: -20px;
}
nav ul li a {
display: block;
background-color: transparent;
}
.group:hover nav ul li a {
--tw-bg-opacity: 1;
background-color: rgba(156, 163, 175, var(--tw-bg-opacity));
--tw-text-opacity: 1;
color: rgba(255, 255, 255, var(--tw-text-opacity));
}
nav ul li:hover > a {
--tw-text-opacity: 1;
color: rgba(17, 24, 39, var(--tw-text-opacity));
}
nav ul li ul ul {
top: 0px;
right: -180px;
left:auto;
}
/* nav ul li ul li {
width: 100%;
} */
nav ul li img {
position: absolute;
right: 10px;
top: calc(50% - 4px);
}
/* end nav */
Also see: Tab Triggers