kitbash Sign in Connect agent
Components

Two-part bar

A bar of two equal cells, violet for the active one and grey for the other, that sticks to the top for the rest of the page. Under it a centred serif title and statement; choosing the other cell cross-fades to its own title.

Part of the style

Violet Difference

7 parts that belong together, with their tokens, type and rules.

Preview

Code
<style>
/* Goes after the pack's base.css */
@import url("https://fonts.googleapis.com/css2?family=Archivo+Narrow:ital,wght@0,400..700;1,400..700&family=Sixtyfour:BLED,SCAN@0..100,-53..100&family=Workbench:BLED,SCAN@0..100,-53..100&display=swap");
:root {
  --paper: #530007;
  --ink: #fff2f0;
  --idle: #742f2c;
  --tray: #5c0f11;
  --plate: #975954;
  --violet: #d34442;
  --font-mark: "Archivo Narrow", "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
  --font-caps: "Archivo Narrow", "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
  --font-text: "Archivo Narrow", "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
}
</style>

<section class="tabs">
  <div class="tabs__bar" role="tablist" aria-label="Sections">
    <button class="tabs__cell is-active" type="button" role="tab" aria-selected="true">Quarries</button>
    <button class="tabs__cell" type="button" role="tab" aria-selected="false">Stockists</button>
  </div>
  <div class="tabs__panels">
    <div class="tabs__panel is-active" role="tabpanel">
      <h2 class="tabs__title">Stone with a home address</h2>
      <p class="tabs__statement">A short list of family quarries, each still cutting the hill its own village was built&nbsp;from.</p>
    </div>
    <div class="tabs__panel" role="tabpanel" aria-hidden="true">
      <h2 class="tabs__title">See it before you spec it</h2>
      <p class="tabs__statement">Yards and showrooms that keep our slabs on the floor, where you can walk round them, not in a&nbsp;catalogue.</p>
    </div>
  </div>
</section>

<style>
  /* With more of the page below it, the root makes no box, so the bar stays stuck all the way down instead of leaving with this section. */
  .tabs:has(~ :not(style, script)) {
    display: contents;
  }

  .tabs__bar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .tabs__cell {
    min-height: var(--bar);
    padding: 0 var(--gutter);
    border: 0;
    border-radius: 0;
    background: var(--idle);
    color: var(--ink);
    font-family: var(--font-caps);
    font-size: var(--caps-m);
    line-height: 1;
    text-transform: uppercase;
    cursor: pointer;
  }

  /* Violet marks the active cell until the pointer enters the bar; then it follows the pointer. The swap is instant. */
  .tabs__bar:not(:hover) .tabs__cell.is-active,
  .tabs__cell:hover,
  .tabs__cell:focus-visible {
    background: var(--violet);
  }
  .tabs__cell:focus-visible {
    outline: var(--rule) solid var(--ink);
    outline-offset: calc(-4 * var(--rule));
  }
  @media (hover: none) {
    .tabs__cell.is-active {
      background: var(--violet);
    }
    .tabs__cell:not(.is-active):hover {
      background: var(--idle);
    }
  }

  .tabs__panels {
    display: grid;
    padding: var(--space-xl) var(--gutter);
    background: var(--paper);
    font-family: var(--font-caps);
    line-height: var(--leading-caps);
    text-align: center;
    text-transform: uppercase;
  }
  .tabs__panel {
    grid-area: 1 / 1;
    align-self: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--time) var(--ease), visibility 0s var(--time);
  }
  .tabs__panel.is-active {
    opacity: 1;
    visibility: visible;
    transition-delay: 0s;
  }
  .tabs__title {
    margin: 0 0 var(--space-m);
    font-size: var(--caps-xxl);
    font-weight: 400;
    line-height: 1;
    text-wrap: balance;
  }
  .tabs__statement {
    max-width: 53rem;
    margin: 0 auto;
    font-size: var(--caps-s);
    line-height: 1.3;
    text-wrap: balance;
  }

  @media (prefers-reduced-motion: reduce) {
    .tabs__panel {
      transition-duration: 0s;
      transition-delay: 0s;
    }
  }
</style>

<script>
(() => {
  document.querySelectorAll(".tabs").forEach((root) => {
    const cells = [...root.querySelectorAll(".tabs__cell")];
    const panels = [...root.querySelectorAll(".tabs__panel")];

    const show = (chosen) => {
      cells.forEach((cell, index) => {
        cell.classList.toggle("is-active", index === chosen);
        cell.setAttribute("aria-selected", String(index === chosen));
      });
      panels.forEach((panel, index) => {
        panel.classList.toggle("is-active", index === chosen);
        panel.toggleAttribute("aria-hidden", index !== chosen);
      });
    };

    cells.forEach((cell, index) => cell.addEventListener("click", () => show(index)));
  });
})();
</script>

Similar components

Theme flood

Theme flood

Showcase with progress tabs

Showcase with progress tabs

Instrument panel

Instrument panel

Keypad and knob

Keypad and knob

Services table

Services table

Word-by-word testimonial

Word-by-word testimonial

Flavour picker

Flavour picker

Chapter stepper

Chapter stepper