kitbash Sign in Connect agent
Components

Fret tiles

Two square tiles with big radii, each a fade between two colours with a soft picture printed in the same two, a stepped fret border drawn to fit by the script, a serif title, one line and an italic link. The picture grows slightly on hover.

Part of the style

Dusk Sky Stadium

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

Preview

Code
<style>
/* Goes after the pack's base.css */
:root {
  --ink: #000000;
  --ink-soft: #060102;
  --mist: #f6793b;
  --stone: #d86932;
  --stone-shade: #411827;
  --veil: rgba(0, 0, 0, 0.34);
  --teal: #4f1c01;
  --sun: #b68d7b;
  --moss: #5b3c2e;
  --rose: #a9684a;
}
</style>

<section class="tiles" aria-label="Where to go">
  <ul class="tiles__list">
    <li class="tiles__item">
      <a class="tiles__tile tiles__tile--dusk" href="#">
        <svg class="tiles__view" viewBox="0 0 600 600" preserveAspectRatio="xMidYMid slice" aria-hidden="true" focusable="false">
          <defs>
            <filter id="tiles-soft" x="-10%" y="-10%" width="120%" height="120%"><feGaussianBlur stdDeviation="3.2" /></filter>
            <filter id="tiles-haze" x="-30%" y="-30%" width="160%" height="160%"><feGaussianBlur stdDeviation="22" /></filter>
          </defs>
          <g filter="url(#tiles-soft)">
            <path class="tiles__dark" d="M0 0h600v150C520 200 470 150 400 190S250 170 190 210 60 190 0 230Z" opacity="0.5" />
            <ellipse class="tiles__light" cx="300" cy="452" rx="262" ry="132" opacity="0.5" />
            <ellipse class="tiles__dark-line" cx="300" cy="452" rx="262" ry="132" stroke-width="26" opacity="0.5" />
            <ellipse class="tiles__light-line" cx="330" cy="462" rx="78" ry="28" stroke-width="5" opacity="0.6" />
            <ellipse class="tiles__light-line" cx="330" cy="466" rx="138" ry="54" stroke-width="4" opacity="0.4" />
            <ellipse class="tiles__light-line" cx="330" cy="470" rx="196" ry="84" stroke-width="3" opacity="0.25" />
            <path class="tiles__dark" d="M304 440a27 27 0 1 1 54 0c24 6 38 20 42 38H262c4-18 18-32 42-38Z" opacity="0.8" />
            <path class="tiles__light-line" d="M96 470V350c0-44 56-44 56 0M152 482V362" stroke-width="9" opacity="0.7" />
            <path class="tiles__dark" d="M440 600c10-70 60-120 160-140v140Z" opacity="0.45" />
          </g>
          <g filter="url(#tiles-haze)">
            <ellipse class="tiles__light" cx="210" cy="356" rx="150" ry="34" opacity="0.26" />
            <ellipse class="tiles__light" cx="430" cy="340" rx="130" ry="30" opacity="0.2" />
          </g>
        </svg>
        <span class="tiles__fret" aria-hidden="true">
          <svg class="tiles__fret-line" focusable="false"><path class="tiles__fret-path" /></svg>
        </span>
        <span class="tiles__words">
          <strong class="tiles__title">Hot pools</strong>
          <span class="tiles__line">Soak until the lamps come on along the rail.</span>
          <span class="tiles__more">See the pools</span>
        </span>
      </a>
    </li>
    <li class="tiles__item">
      <a class="tiles__tile tiles__tile--noon" href="#">
        <svg class="tiles__view" viewBox="0 0 600 600" preserveAspectRatio="xMidYMid slice" aria-hidden="true" focusable="false">
          <g filter="url(#tiles-soft)">
            <path class="tiles__dark" d="M40 60c50-34 104-30 150 6-54 30-106 28-150-6ZM250 30c56-22 108-8 144 36-58 18-108 6-144-36ZM430 110c44-40 96-48 150-22-42 42-94 50-150 22ZM120 170c34-44 82-60 140-46-30 48-78 64-140 46ZM330 190c48-30 98-28 142 8-50 28-98 26-142-8Z" opacity="0.22" />
            <ellipse class="tiles__dark" cx="300" cy="446" rx="270" ry="128" opacity="0.3" />
            <ellipse class="tiles__light-line" cx="300" cy="446" rx="246" ry="112" stroke-width="4" opacity="0.4" />
            <path class="tiles__dark" d="M196 420c-34-4-50 12-50 30s18 32 52 26ZM372 420l66-38 14 18-66 50Z" opacity="0.6" />
            <ellipse class="tiles__dark" cx="290" cy="440" rx="96" ry="60" opacity="0.72" />
            <ellipse class="tiles__light-line" cx="290" cy="428" rx="56" ry="30" stroke-width="5" opacity="0.55" />
            <ellipse class="tiles__light" cx="290" cy="420" rx="14" ry="9" opacity="0.7" />
            <ellipse class="tiles__dark" cx="474" cy="486" rx="46" ry="26" opacity="0.62" />
            <ellipse class="tiles__light" cx="474" cy="482" rx="34" ry="17" opacity="0.6" />
            <ellipse class="tiles__dark" cx="140" cy="506" rx="42" ry="24" opacity="0.62" />
            <ellipse class="tiles__light" cx="140" cy="502" rx="31" ry="16" opacity="0.6" />
          </g>
          <g filter="url(#tiles-haze)">
            <ellipse class="tiles__light" cx="300" cy="330" rx="90" ry="30" opacity="0.35" />
          </g>
        </svg>
        <span class="tiles__fret" aria-hidden="true">
          <svg class="tiles__fret-line" focusable="false"><path class="tiles__fret-path" /></svg>
        </span>
        <span class="tiles__words">
          <strong class="tiles__title">Tea garden</strong>
          <span class="tiles__line">Six teas, one soup and bread from the stone oven.</span>
          <span class="tiles__more">See the table</span>
        </span>
      </a>
    </li>
  </ul>
</section>

<style>
  .tiles {
    padding: calc(var(--section-space) / 2) var(--gutter);
  }
  .tiles__list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--gap);
    margin: 0;
    padding: 0;
    list-style: none;
  }

  /* Tile: a square with a two-colour fade and a picture printed in the same two colours. */
  .tiles__tile {
    position: relative;
    isolation: isolate;
    display: block;
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: var(--radius-tile);
    text-decoration: none;
  }
  .tiles__tile--dusk {
    background: linear-gradient(var(--teal) 50%, var(--sun) 96%);
    color: var(--sun);
  }
  .tiles__tile--noon {
    background: linear-gradient(var(--sun) 28%, var(--moss));
    color: var(--teal);
  }
  .tiles__tile::after {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--grain);
    opacity: var(--grain-strength);
    mix-blend-mode: overlay;
    pointer-events: none;
  }
  .tiles__view {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    transition: scale var(--time-intro) var(--ease-intro);
  }
  .tiles__tile:hover .tiles__view,
  .tiles__tile:focus-visible .tiles__view {
    scale: 1.04;
  }
  .tiles__dark { fill: var(--teal); }
  .tiles__light { fill: var(--sun); }
  .tiles__dark-line,
  .tiles__light-line {
    fill: none;
    stroke-linecap: round;
  }
  .tiles__dark-line { stroke: var(--teal); }
  .tiles__light-line { stroke: var(--sun); }

  /* Fret: a stepped line running round the tile. Plain border until the script has drawn the steps. */
  .tiles__fret {
    position: absolute;
    inset: clamp(1rem, 2vw, 1.75rem);
    border: var(--line-fret) solid currentColor;
    font-size: var(--fret-step);
  }
  .tiles__fret.is-drawn {
    border-color: transparent;
  }
  .tiles__fret-line {
    position: absolute;
    inset: calc(var(--line-fret) * -1);
    width: calc(100% + var(--line-fret) * 2);
    height: calc(100% + var(--line-fret) * 2);
    overflow: visible;
  }
  .tiles__fret-path {
    fill: none;
    stroke: currentColor;
    stroke-width: var(--line-fret);
    stroke-linejoin: miter;
  }

  .tiles__words {
    position: absolute;
    inset: 0;
    display: grid;
    align-content: start;
    justify-items: center;
    padding: 17% 13% 0;
    text-align: center;
  }
  .tiles__title {
    font-family: var(--font-display);
    font-size: var(--display-l);
    font-weight: 400;
    line-height: 0.9;
  }
  .tiles__line {
    max-width: 16em;
    margin-top: var(--space-s);
    font-family: var(--font-display);
    font-size: var(--text-m);
    line-height: var(--leading-tight);
    text-wrap: balance;
  }
  .tiles__more {
    margin-top: var(--space-l);
    font-family: var(--font-display);
    font-size: var(--text-s);
    font-style: italic;
    line-height: var(--leading-tight);
  }
  .tiles__tile:hover .tiles__more,
  .tiles__tile:focus-visible .tiles__more {
    font-style: normal;
  }
  .tiles__tile:focus-visible {
    outline: var(--line-focus) solid var(--ink);
    outline-offset: var(--line-focus);
  }

  @media (max-width: 39.99rem) {
    .tiles__list {
      grid-template-columns: minmax(0, 1fr);
    }
    .tiles__words {
      padding-top: 19%;
    }
    .tiles__more {
      margin-top: var(--space-m);
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .tiles__view {
      transition: none;
    }
    .tiles__tile:hover .tiles__view,
    .tiles__tile:focus-visible .tiles__view {
      scale: 1;
    }
  }
</style>

<script>
  (() => {
    const EDGES = [
      { along: [1, 0], inward: [0, 1] },
      { along: [0, 1], inward: [-1, 0] },
      { along: [-1, 0], inward: [0, -1] },
      { along: [0, -1], inward: [1, 0] },
    ];
    const line = ([x, y], length) => `l${(x * length).toFixed(2)} ${(y * length).toFixed(2)}`;

    /* An odd number of runs, so every edge starts and ends on the outside and the corners match. */
    const oddRuns = (length, step) => {
      const runs = Math.max(3, Math.round(length / step));
      return runs % 2 ? runs : runs + 1;
    };
    const steppedEdge = ({ along, inward }, length, step) => {
      const runs = oddRuns(length, step);
      return Array.from({ length: runs }, (_, index) => {
        const isLast = index === runs - 1;
        const turn = index % 2 ? -step : step;
        return line(along, length / runs) + (isLast ? "" : line(inward, turn));
      }).join("");
    };
    const steppedFrame = (width, height, step) =>
      `M0 0${EDGES.map((edge) => steppedEdge(edge, edge.along[0] ? width : height, step)).join("")}Z`;

    const drawFret = (fret) => {
      const svg = fret.querySelector(".tiles__fret-line");
      const path = fret.querySelector(".tiles__fret-path");
      const stroke = parseFloat(getComputedStyle(path).strokeWidth);
      const step = parseFloat(getComputedStyle(fret).fontSize);
      const { width, height } = svg.getBoundingClientRect();
      if (!width || !height) return;
      svg.setAttribute("viewBox", `${-stroke / 2} ${-stroke / 2} ${width} ${height}`);
      path.setAttribute("d", steppedFrame(width - stroke, height - stroke, step));
      fret.classList.add("is-drawn");
    };

    document.querySelectorAll(".tiles").forEach((root) => {
      const redraw = new ResizeObserver((entries) => entries.forEach((entry) => drawFret(entry.target)));
      root.querySelectorAll(".tiles__fret").forEach((fret) => redraw.observe(fret));
    });
  })();
</script>

Similar components

News cards

News cards

Three movements

Three movements

Card rail

Card rail

Feature cards

Feature cards

Feature cells

Feature cells

Project panes

Project panes

Edition slips

Edition slips

Dispatches

Dispatches