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.
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.
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.
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.
<template>
<aside
class="sidebar"
@click="activeItem=0"
>
<div class="logo"><svg viewBox="0 0 89 59" width="89" height="59" xmlns="http://www.w3.org/2000/svg"><path d="M59.258 58.406H0V.594h59.258L88.164 29.5 59.258 58.406zM78.086 29.5L55.898 7.312H6.758v44.336h49.14L78.086 29.5zm-42.422 4.766L23.086 46.844l-4.766-4.766L30.898 29.5 18.32 16.922l4.766-4.766 12.578 12.578 12.578-12.578 4.766 4.766L40.43 29.5l12.578 12.578-4.766 4.766-12.578-12.578z" fill="currentColor" fill-rule="nonzero"></path></svg></div>
<fieldset>
<legend>Columns ({{itemNum}})</legend>
<input type="range" v-model="itemNum" min="2" max="25" step="1"/>
</fieldset>
<fieldset>
<legend>Hover displace ({{itemHoverDisplace}}%)</legend>
<input type="range" v-model="itemHoverDisplace" min="0" max="10" step=".5"/>
</fieldset>
<fieldset>
<legend>Collapsed size ({{itemTranslateCollapsed}}%)</legend>
<input type="range" v-model="itemTranslateCollapsed" min="0" max="20" step="1"/>
</fieldset>
</aside>
<main class="accordion"
:style="{
'--item-num': parseInt(itemNum),
'--hover-displace': `${itemHoverDisplace}%`,
'--item-translate-collapsed': `${itemTranslateCollapsed}%`,
'--item-translate': 'calc(100% / var(--item-num))'
}"
:class="activeItem > 0 && 'accordion--open'"
>
<div
class="accordion__item"
v-for="index in parseInt(itemNum)"
:key="index"
:style="`--index: ${index}; background-color: #${colors[index]}`"
:class="index === activeItem && 'accordion__item--open'"
@click="activeItem=index"
>
<div class="accordion__item__content"><h1>Item {{index}}</h1>
<h3>Straight text</h3>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.</p></div>
</div>
</main>
</template>
<script setup>
import { computed, ref,watch } from "vue"
const itemNum = ref(5);
const itemHoverDisplace = ref(1);
const itemTranslateCollapsed = ref(4);
const activeItem = ref(0);
const colors = [...Array(100).keys()].map((i) => Math.floor(Math.random() * 16777215).toString(16))
</script>
<style lang="scss">
.accordion {
flex: 1;
background: silver;
height: 100%;
--item-translate-collapsed: 4%;
--hover-displace: 1%;
&--open {
--item-translate: var(--item-translate-collapsed)!important;
}
&__item {
$item: &;
position: absolute;
z-index: var(--index, 1);
overflow: hidden;
height: 100%;
padding: 1rem;
box-shadow: 0 0 2rem rgba(0 0 0 / 50%);
background: maroon;
transform: translateX(calc(var(--item-translate) * (var(--index) - 1)));
transition: transform .4s;
&:not(#{$item}--open):hover {
cursor: pointer;
transform: translate(calc(var(--item-translate) * (var(--index) - 1) - var(--hover-displace)));
}
&--open ~ #{$item} {
transform: translate(calc(100% - ((var(--item-num) - var(--index) + 1) * var(--item-translate-collapsed))));
&:hover {
transform: translate(calc(100% - ((var(--item-num) - var(--index) + 1) * var(--item-translate-collapsed)) - var(--hover-displace)));
}
}
&__content {
margin-inline-end: calc((var(--item-num) - 1) * var(--item-translate-collapsed));
}
}
}
.sidebar {
background: white;
}
.logo {
background: black;
color: white;
aspect-ratio: 1;
border-radius: 50%;
padding: .5rem;
margin: 2rem 1rem;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
max-width: 60px;
svg { max-width: 70%; transform: translateX(8%); }
}
fieldset {
display: flex;
margin: 1rem;
button {
flex: 1;
margin: .2rem;
}
}
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
color: #2c3e50;
height: 100%;
display: flex;
}
html, body, #app {
height: 100%;
overflow: hidden;
}
</style>
Also see: Tab Triggers