Skip to content

Pinned section with an evolving background in WordPress

The key message stays pinned while the background changes colour and illustration at each scroll step. CSS sticky, a light script, stacked cards as fallback under prefers-reduced-motion.

Here is an excerpt of this component's code in WordPress. The full code is free for members, ready to copy into your project.

This component also comes in

Open in a new tab

The code in WordPress

features-sections-epinglees-fond-evolutif.php
<?php
/**
 * Plugin Name: Forge, Section épinglée à fond évolutif
 * Description: Le message clé reste épinglé pendant que le fond change de couleur et d’illustration à chaque étape du défilement. CSS sticky, script léger, repli en cartes empilées sous prefers-reduced-motion. Ajoute la composition « Section épinglée à fond évolutif » à l'éditeur de blocs.
 * Version: 1.0.0
 * Requires at least: 6.6
 * Requires PHP: 8.1
 * Author: Forge
 * License: GPL-2.0-or-later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: forge-features-sections-epinglees-fond-evolutif
 *
pattern.html
<!-- wp:html -->
<section class="sefe" aria-labelledby="sefe-titre" data-sefe>
        <div class="sefe__track">
          <div class="sefe__stage">
            <div class="sefe__backs" aria-hidden="true" data-sefe-backs></div>
            <div class="sefe__message">
              <p class="sefe__eyebrow">Atelier Valère · Salles de bain à Nantes</p>
              <h2 class="sefe__title" id="sefe-titre">Un seul artisan, de la première visite au dernier joint</h2>
              <p class="sefe__lead">Pas de sous-traitance en cascade : la personne qui mesure votre pièce est celle qui pose le carrelage et vous rend les clés.</p>
              <a class="sefe__cta" href="#contact">Demander une visite gratuite</a>
              <div class="sefe__meter" aria-hidden="true" data-sefe-meter hidden><span class="sefe__meter-fill"></span></div>
            </div>
script.js
(() => {
  if (!document.querySelector(".sefe")) return;
  for (const root of document.querySelectorAll("[data-sefe]")) {
    const steps = [...root.querySelectorAll("[data-sefe-step]")];
    const cards = steps.map((step) => step.firstElementChild);
    const backs = root.querySelector("[data-sefe-backs]");
    const meter = root.querySelector("[data-sefe-meter]");
    const reduced = window.matchMedia("(prefers-reduced-motion: reduce)");
    // On a very short or heavily zoomed window the pinned message would cover the steps.
    const tall = window.matchMedia("(min-height: 30rem)");
    // Each background layer reuses the colours and the drawing of its step: nothing to keep in sync by hand.
    const layers = steps.map((step, i) => {
style.css
:root {
  --sefe-paper: #fffaf2;
  --sefe-text: #1e1a17;
  --sefe-muted: #3f3832;
  --sefe-accent: #6a2a0a;
  --sefe-line: #d9c8b0;
  --sefe-t1: #f4e8d6;
  --sefe-s1: #e7d3b6;
  --sefe-i1: #c4a985;
  --sefe-t2: #e2ecdf;
  --sefe-s2: #cbdcc6;
  --sefe-i2: #9fb998;

Free component: copy it freely, including for commercial projects.

Features components in WordPress
  • Three cards in saturated flat colours (yellow, pink, electric blue) with high-contrast text and a dark variant. Every colour pair is measured at AA: 5.5:1 at worst.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Six features as frosted glass cards over a slowly drifting aurora mesh gradient. Pause button, still background under prefers-reduced-motion, CSS and a light script.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A six-cell bento grid: key figures, SVG sparklines, a quote and icons. All the text is in the HTML and the animation is CSS only, with no script at all.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A two-offer table: checked rows, a column highlighted from top to bottom and one call-to-action button per offer. Pure HTML and CSS, no script at all.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A magazine-style article: title band, standfirst, drop cap, subheadings and a pull quote, set in three columns of equal height. Pure CSS, no script at all.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A simulator that estimates the heating bill and the yearly savings in euros from the floor area, current energy and chosen works.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component