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.
<body>
<div class="liquid">
<h1>Liquid</h1>
<h2>Un gabarit en Grid Layout</h2>
<p><strong>[Trouver un nom]</strong> est le nom d'un agencement réalisé en CSS Grid Layout compatible avec l'affichage de blocs qui "sortent" de la maquette, généralement appelés <i lang="en">full-bleed</i>, <i lang="en">breakout</i>, <i lang="en">hero</i> ou <i lang="en">splash</i>.</p>
<p>Caractéristiques du gabarit <code>.liquid</code> :</p>
<ul>
<li>Le conteneur <code>.liquid</code> a une largeur de contenu maximum (<code>--liquid-content</code>) et est centré dans la fenêtre. Le contenu "classique" s'y place automatiquement.</li>
<li>Un espace minimum de côté (<code>--liquid-spacer</code>) est toujours présent afin que le conteneur ne soit pas collé aux bords de fenêtre sur des petits écrans.</li>
<li>Un enfant <code>.splash</code> déborde de la zone de contenu et occupe tout liquid.</li>
<li><code>.liquid</code> peut être appliqué sur n'importe quel conteneur, voire sur <code>body</code>.</li>
</ul>
<section class="splash">
<p>Un élément de classe <code>.splash</code> déborde de la zone de contenu et occupe tout liquid :<br><code>.splash {grid-column: liquid-start / liquid-end;}</code></p>
<p>Son contenu s'aligne sur la zone de contenu générale.</p>
</section>
<p>Les variantes <code>.splash-start</code> et <code>.splash-end</code> permettent de placer les enfants d'un côté ou de l'autre de liquid.</p>
<section class="splash-start">
<p>Un élément de classe <code>.splash-start</code> se place au début de liquid :<br><code>.splash-start {grid-column: liquid-start / content-end;}</code></p>
</section>
<section class="splash-end">
<p>Un élément de classe <code>.splash-end</code> se place à la fin de liquid :<br><code>.splash-end {grid-column: content-start / liquid-end;}</code></p>
</section>
<p>Les variantes <code>.splash-half-start</code> et <code>.splash-half-end</code> permettent de placer les enfants d'un côté ou de l'autre de liquid, de part et d'autre du milieu de page.</p>
<section class="splash-half-start">
<p>Un élément de classe <code>.splash-half-start</code> se place au début de liquid et s'arrête en milieu de page :<br><code>.splash-half-start {grid-column: liquid-start / half;}</code></p>
</section>
<section class="splash-half-end">
<p>Un élément de classe <code>.splash-half-end</code> débute en milieu de page et termine au fin de liquid :<br><code>.splash-half-end {grid-column: half / liquid-end;}</code></p>
</section>
<img class="hero-img splash" src="https://assets.codepen.io/9425/air.jpeg" alt="">
<pre><code>.liquid {
--liquid-min-margin: 2rem;
--liquid-content: 840px;
display: grid;
grid-template-columns:
[liquid-start] minmax(var(--liquid-min-margin), 1fr)
[content-start] minmax(0, calc(var(--liquid-content) / 2))
[half] minmax(0, calc(var(--liquid-content) / 2))
[content-end] minmax(var(--liquid-min-margin), 1fr)
[liquid-end];
}</code></pre>
<h2 id="tuto">Comment ça marche ?</h2>
<p><i>TL;DR: Affichez la grille.</i></p>
<p>La grille principale contient tous les éléments et est découpée en <strong>quatre colonnes</strong> :</p>
<ul>
<li>Les <b>deux colonnes latérales</b> ont une taille fluide, variant de <code>2rem</code> (en vrai il s'agit d'une variable) jusqu'à <code>1fr</code>. Cela signifie que ces deux colonnes occupent tout l'espace disponible dans la fenêtre, avec un minimum incompressible de "2rem"</li>
<li>Les <b>deux colonnes centrales</b> réunies occupent une largeur fluide variant de <code>auto</code> (la taille minimale pour le contenu) jusqu'à <code>840px</code> dans notre démo. En clair, c'est dans cette zone que va se placer l'ensemble des contenus de la page afin qu'ils occupent 840px de large tout en demeurant fluides si la fenêtre se réduit.</li>
<li>Les lignes verticales qui séparent ces 4 colonnes sont <b>nommées</b> (ce sont les valeurs entre crochets que l'on lit dans le code de la grille). La première ligne tout à gauche s'appelle <code>[liquid-start]</code>, la suivante <code>[content-start]</code> et ainsi de suite jusqu'à la dernière tout à droite qui est <code>[liquid-end]</code>.</li>
<li>Les éléments enfants de la grille pauvent ainsi être facilement positionnés en indiquant la ligne de départ et la ligne d'arrivée, par exemple <code>.splash-start {grid-column: liquid-start / content-end;}</code>. Tadaam !</li>
</ul>
<footer class="splash" role="contentinfo">
<p>liquid est un gabarit conçu par Alsacréations, inspiré de plein d'exemples sur Codepen.</p>
</footer>
</div>
<div class="debug-group">
<input id="debug" type="checkbox">
<label for="debug">Show grid</label>
</div>
<div class="liquid debug">
<div class="splash">
<code class="hint hint-splash-start">minmax(var(--liquid-spacer), 1fr)</code>
<code class="hint hint-splash-end">minmax(var(--liquid-spacer), 1fr)</code>
</div>
<div class="content">
<code class="hint hint-content-start">minmax(auto, calc(var(--liquid-content) / 2))</code>
<code class="hint hint-content-end">minmax(auto, calc(var(--liquid-content) / 2))</code>
</div>
</div>
</body>
.liquid {
--liquid-min-margin: 2rem;
--liquid-content: 840px;
display: grid;
grid-template-columns:
[liquid-start] minmax(var(--liquid-min-margin), 1fr)
[content-start] minmax(0, calc(var(--liquid-content) / 2))
[half] minmax(0, calc(var(--liquid-content) / 2))
[content-end] minmax(var(--liquid-min-margin), 1fr)
[liquid-end];
& > * {
grid-column: content;
}
}
/* Splash items */
.splash,
.splash-start,
.splash-end,
.splash-half-start,
.splash-half-end {
display: grid;
grid-template-columns: subgrid;
& > * {
grid-column: content;
}
}
.splash {
grid-column: liquid;
}
.splash-start {
grid-column: liquid-start / content-end;
}
.splash-end {
grid-column: content-start / liquid-end;
}
.splash-half-start {
grid-column: liquid-start / half;
& > * {
grid-column: content-start / half;
}
}
.splash-half-end {
grid-column: half / liquid-end;
& > * {
grid-column: half / content-end;
}
}
/* Hero image */
.hero-img {
justify-self: center;
width: 100%;
max-height: 400px;
object-fit: cover;
}
/* ---- Debug styles ---- */
/* Thanks to https://codepen.io/hexagoncircle/pen/dyejrpE?editors=1100 */
.debug {
--theme: SaddleBrown;
--pseudo-offset: 0.25rem;
position: fixed;
top: 0;
left: 0;
grid-template-rows: 1fr;
width: 100%;
height: 100vh;
opacity: 0;
z-index: -1;
transition: 0.3s ease-out;
transition-property: opacity, background, backdrop-filter;
backdrop-filter: blur(4px);
//mix-blend-mode: multiply;
}
.debug > * {
position: relative;
height: 100vh;
margin: 0;
grid-row: 1 / -1;
border-radius: 0;
border-inline: 2px dashed var(--theme);
}
.debug > *::before,
.debug > *::after {
content: var(--column) var(--suffix);
position: absolute;
z-index: 3000;
top: 50%;
writing-mode: vertical-lr;
padding: 12px 4px;
text-transform: uppercase;
font-size: 0.8em;
transform: translateY(-50%);
color: #fff;
background-color: var(--theme);
border-radius: 4px;
}
.debug::before,
.debug::after {
content: "";
position: absolute;
z-index: 3000;
top: 0;
left: 50vw;
}
.debug::before {
border-left: 2px dashed var(--theme);
height: 100vh;
}
.debug::after {
content: "Half";
top: 50vh;
translate: var(--pseudo-offset) -50%;
padding: 8px 4px;
text-transform: uppercase;
writing-mode: vertical-lr;
font-size: 0.8em;
color: #fff;
background-color: var(--theme);
border-radius: 4px;
}
.debug > *::before {
left: var(--pseudo-offset);
--suffix: "-start"
}
.debug > *::after {
right: var(--pseudo-offset);
--suffix: "-end"
}
.debug > *:nth-child(2) {
--column: "Content";
background: rgb(139 69 19 / 10%);
//background: burlywood;
}
.debug > *:nth-child(1) {
--column: "liquid";
background: rgb(139 69 19 / 20%);
//background: tan;
}
[id="debug"],
[id="debug"] + label {
cursor: pointer;
user-select: none;
}
[class="debug-group"] {
position: fixed;
top: 0; left: 0;
z-index: 2000;
padding: 0.5rem 1rem;
background: rgb(255 255 255 / 30%);
}
/* Hints positionning */
.debug .hint {
position: fixed;
overflow-x: hidden;
font-weight: 400;
bottom: 0;
left: 0;
right: 0;
margin: 0;
padding: 4px 10px;
border-radius: 4px;
font-size: 0.7em;
color: #fff;
background: var(--theme);
}
.debug .hint-splash-start {
grid-column-start: 1;
grid-column-end: 2;
}
.debug .hint-splash-end {
grid-column-start: -2;
grid-column-end: -1;
}
.debug .hint-content-start {
grid-column-start: 2;
grid-column-end: 3;
}
.debug .hint-content-end {
grid-column-start: -3;
grid-column-end: -2;
}
body:has([id="debug"]:checked) .debug {
opacity: 1;
z-index: 1000;
}
/* Reset */
@layer reset {
*,
*::before,
*::after {
box-sizing: border-box;
min-width: 0;
}
body {
margin: 0;
padding: 0;
font-size: 1.2rem;
line-height: 1.5;
font-family: system-ui, sans-serif;
background: #ddd;
color: #222;
}
img {
max-width: 100%;
height: auto;
}
button {
border: 0;
padding: 0;
line-height: 0;
background: transparent;
cursor: pointer;
}
:where(
img,
table,
td,
blockquote,
pre,
code,
input,
textarea,
select,
video,
svg,
iframe) {
max-width: 100%;
}
:where(pre, code, kbd, samp) {
font-family: monospace, monospace;
font-size: 1em;
}
:where(pre) {
tab-size: 2;
white-space: pre-wrap;
line-height: normal;
overflow: auto;
}
}
/* Deco */
@layer deco {
h1 {
margin-bottom: 0;
font-family: georgia, serif;
text-align: center;
font-size: 4rem;
font-weight: 300;
}
h2 {
margin-block: 1rem 3rem;
font-family: georgia, serif;
text-align: center;
font-weight: 300;
}
p {
margin-block: 0 1rem;
}
ul {
margin: 0;
}
.splash {
margin-block: 1rem;
padding-top: 1rem;
font-weight: 300;
background: #333;
color: #fff;
}
[class*="splash-"] {
padding-top: 1rem;
margin-bottom: 1rem;
text-align: left;
font-weight: 300;
background: sienna;
color: #fff;
}
[class*="-end"] {
background: DarkSlateGray;
}
pre {
padding: 1rem;
margin-inline: 0;
text-align: left;
font-weight: 300;
background: #333;
color: #fff;
border-radius: 10px;
}
code {
font-family: monospace, monospace;
font-size: smaller;
font-weight: 700;
}
footer {
padding: 1rem;
margin-inline: 0;
margin-bottom: 0 !important;
font-weight: 300;
background: #000;
color: #fff;
}
}
Also see: Tab Triggers