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="module_accordion">
<input type="radio" name="module_accordion" id="module_accordion_1" />
<section class="mod_acc_section">
<label class="mod_acc_header" for="module_accordion_1">
<label class="mod_acc_header_close" for="module_accordion_close"></label>
<div class="mod_acc_title"><img src="https://cyrillucas.com/projects/accordion/list.svg" alt="list" />Title 1</div>
<img src="https://cyrillucas.com/projects/accordion/arrow_right.svg" alt="arrow-right" class="mod_acc_arrow" />
</label>
<div class="mod_acc_content">
Start content 1<br />.<br />.<br />.<br />.<br />.<br />End content 1
<label for="module_accordion_close">
<img src="https://cyrillucas.com/projects/accordion/close.svg" alt="close" class="close_content" />
</label>
</div>
</section>
<input type="radio" name="module_accordion" id="module_accordion_2" />
<section class="mod_acc_section">
<label class="mod_acc_header" for="module_accordion_2">
<label class="mod_acc_header_close" for="module_accordion_close"></label>
<div class="mod_acc_title"><img src="https://cyrillucas.com/projects/accordion/list.svg" alt="list" />Title 2</div>
<img src="https://cyrillucas.com/projects/accordion/arrow_right.svg" alt="arrow_right" class="mod_acc_arrow" />
</label>
<div class="mod_acc_content">
Start content 2<br />.<br />.<br />.<br />.<br />.<br />End content 2
<label for="module_accordion_close">
<img src="https://cyrillucas.com/projects/accordion/close.svg" alt="close" class="close_content" />
</label>
</div>
</section>
<input type="radio" name="module_accordion" id="module_accordion_3" />
<section class="mod_acc_section">
<label class="mod_acc_header" for="module_accordion_3">
<label class="mod_acc_header_close" for="module_accordion_close"></label>
<div class="mod_acc_title"><img src="https://cyrillucas.com/projects/accordion/list.svg" />Title 3</div>
<img src="https://cyrillucas.com/projects/accordion/arrow_right.svg" alt="arrow_right" class="mod_acc_arrow" />
</label>
<div class="mod_acc_content">
Start content 3<br />.<br />.<br />.<br />.<br />.<br />End content 3
<label for="module_accordion_close">
<img src="https://cyrillucas.com/projects/accordion/close.svg" alt="close" class="close_content" />
</label>
</div>
</section>
<input type="radio" name="module_accordion" id="module_accordion_close" />
</div>
<pre>
-----------------
| PARAMETRAGE |
-----------------
3 variables en début de CSS :
--open_speed : vitesse de déploiement en pixels / seconde.
--max_content_height : hauteur du contenu le plus grand en pixels (valeur arbitraire possible).
=> ces 2 valeurs sont sans unités, qui sont ajoutées dans la fonction calc().
--opacity_speed : vitesse de l'effet transparent => plein au déploiement en secondes.
On est obligé d'utiliser une hauteur fixe, sinon l'effet de transition ne fonctionne pas.
Cependant, max-height au lieu de height permet l'ajustement au contenu.
----------------
| POINT FORTS |
----------------
Pure CSS, pas de JavaScript qui va alourdir le code.
--------------
| DRAWBACK |
--------------
À cause de la hauteur fixe (max-height), il est difficile d'utiliser un effet de
transition pour le repliage. En effet, si max-height = 1000px et le contenu = 300px,
le repliage part de 1000px et non 300px, ce qui crée une latence, différente pour
chaque contenu ayant une hauteur différente.
--------------------
| FONCTIONNEMENT |
--------------------
Déploiement :
'''''''''''
On se sert des boutons radio cachés. Une fois cochés par
l'intermédiaire des en-têtes, ils déplient le contenu associé.
Fermeture :
'''''''''
On coche un bouton radio non-associé à un contenu, qui va décocher les autres. Pour ce faire,
on utilise la fermeture en bas à droite du contenu, ou on clique sur l'en-tête du menu déplié
pour le refermer (un wrapper apparaît sur l'en-tête du menu déplié, et fait cocher le bouton
radio non associé au contenu, puis disparait pour pouvoir recocher le bouton radio.)
! garder z-index: 1 sur le wrapper, car en cas d'images dans l'en-tête, elles passent au
dessus du wrapper dans le flux et bloquent le clic.
</pre>
#module_accordion {
--open_speed: 300; /* pixels per second */
--max_content_height: 2000; /* pixels */
--opacity_speed: 1s;
width: 300px;
margin: auto;
}
#module_accordion input[type="radio"] {
display: none;
}
#module_accordion input[type="radio"]:checked + .mod_acc_section {
margin-top: 10px; margin-bottom: 10px;
box-shadow: 0px 0px 7px grey;
transition: 0.3s;
}
#module_accordion .mod_acc_header {
position: relative;
display: flex; justify-content: space-between; align-items: center;
height: 50px;
padding-left: 10px; padding-right: 10px;
background: grey;
border: 1px solid black;
cursor: pointer;
}
#module_accordion .mod_acc_header_close {
position: absolute; top:0; left:0;
z-index: 1;
display: none;
height: 100%; width: 100%;
cursor: pointer;
}
#module_accordion input[type="radio"]:checked + .mod_acc_section .mod_acc_header_close {
display: block;
}
#module_accordion .mod_acc_title img {
height: 16px; width: 16px;
padding-right: 10px;
}
#module_accordion .mod_acc_title {
font-size: 20px;
}
#module_accordion .mod_acc_arrow {
height: 12px; width: 12px;
}
#module_accordion input[type="radio"]:checked + .mod_acc_section .mod_acc_arrow {
transform: rotateZ(90deg);
transition: transform 0.3s;
}
#module_accordion .mod_acc_content {
max-height: 0px;
overflow: hidden;
background: lightgrey;
opacity: 0%;
}
#module_accordion input[type="radio"]:checked + .mod_acc_section .mod_acc_content {
padding: 5px;
border: 1px solid black; border-top: 0;
max-height: calc(var(--max_content_height) * 1px);
opacity: 100%;
transition: max-height calc(var(--max_content_height) / var(--open_speed) * 1s), opacity var(--opacity_speed);
}
#module_accordion .mod_acc_content .close_content {
float: right;
width: 14px; height: 14px;
cursor: pointer;
}
Also see: Tab Triggers