Skip to content

176 web animation techniques, each a live demo with plain settings and a ready-made prompt for your AI assistant. No dependencies, no build step.

fix: with a coarse pointer each mode button's tap area reaches 10px above and below it (44px with the smallest heading line, nothing moves), and the help line's pull reads the Watch step's gap from --hb-watch-gap

matin0837b7cc86e3
diff --git a/assets/css/demo-page.css b/assets/css/demo-page.css
index 339b3675..eb9dc12f 100644
--- a/assets/css/demo-page.css
+++ b/assets/css/demo-page.css
@@ -55,7 +55,8 @@ body.hb [hidden]{display:none!important}
/* Steps */
.hb-step{display:flex;flex-direction:column;gap:clamp(16px,2.4vw,24px)}
.hb-step+.hb-step{padding-top:clamp(28px,4vw,36px);border-top:1px solid var(--hb-line)}
-.hb-watch{gap:16px}
+/* The Watch step's gap is a custom property, read again by the help line beside the mode switch (from 761px, below) */
+.hb-watch{--hb-watch-gap:16px;gap:var(--hb-watch-gap)}
.hb-step-head{display:flex;align-items:flex-start;gap:14px}
.hb-num{flex:none;display:flex;align-items:center;justify-content:center;width:32px;height:32px;border-radius:50%;
background:var(--hb-accent);color:#0b0b0d;font:800 16px/1 var(--hb-font)}
@@ -248,7 +249,7 @@ textarea.hb-text{min-height:88px;padding:10px 12px;resize:vertical}
14px gap). Nothing in the heading row is taller than the heading line, so the stage stays where it is on a page without the
switch: the switch is stretched to that line (its buttons drop the 44px minimum here; up to 760px, in a row of their own, they
keep it), and the number reaches into the help line's row, as it does there. The help line keeps its 4px under the heading: it
- is pulled up by the gap between the step's rows less 4px (16px less 4px; on a short laptop screen 12px less 4px, below).
+ is pulled up by the gap between the step's rows less 4px, read from --hb-watch-gap (16px, and 12px on a short laptop screen).
A player bar with one or two controls leaves room beside it, so there the note for the mode in view sits next to the bar, under
the switch, and is on a laptop's first screen too. Three columns then: the player bar's own width, the room left over and the
switch's width. The heading spans the first two (the room it had before), the stage spans all three, the player bar keeps the
@@ -263,7 +264,7 @@ textarea.hb-text{min-height:88px;padding:10px 12px;resize:vertical}
.hb-watch:has(> .hb-modes) > .hb-step-head,.hb-watch:has(> .hb-modes) > .hb-step-head > div{display:contents}
.hb-watch:has(> .hb-modes) > .hb-step-head > .hb-num{grid-row:1/span 2;grid-column:1;align-self:start}
.hb-watch:has(> .hb-modes) > .hb-step-head > div > h2{grid-row:1;grid-column:1/-2;margin-left:46px}
- .hb-watch:has(> .hb-modes) > .hb-step-head > div > p{grid-row:2;grid-column:1/-1;margin:-12px 0 0 46px}
+ .hb-watch:has(> .hb-modes) > .hb-step-head > div > p{grid-row:2;grid-column:1/-1;margin:calc(4px - var(--hb-watch-gap)) 0 0 46px}
.hb-watch:has(> .hb-modes) > .hb-modes{grid-row:1;grid-column:2;flex-wrap:nowrap;align-self:stretch}
.hb-watch:has(> .hb-modes) > .hb-modes button{min-height:0}
.hb-watch:has(> .hb-modes):not(:has(> .hb-player > :nth-child(3), > .hb-player > .hb-player-note)){grid-template-columns:auto minmax(0,1fr) auto}
@@ -271,9 +272,13 @@ textarea.hb-text{min-height:88px;padding:10px 12px;resize:vertical}
.hb-watch:has(> .hb-modes):not(:has(> .hb-player > :nth-child(3), > .hb-player > .hb-player-note)) > .hb-player{grid-column:1;align-self:start}
.hb-watch:has(> .hb-modes):not(:has(> .hb-player > :nth-child(3), > .hb-player > .hb-player-note)) > .hb-mode-notes{grid-column:2/-1;align-self:center}
}
-/* A short laptop screen puts 12px between the Watch step's rows (below), so there the help line is pulled up by 12px less 4px */
-@media(min-width:761px) and (max-height:760px){
- .hb-watch:has(> .hb-modes) > .hb-step-head > div > p{margin-top:-8px}
+/* With a coarse pointer (a phone held sideways, a tablet) the mode buttons, only as tall as the heading line from 761px, would be
+ small to tap. So each button's tap area reaches 10px above and below it: an empty ::after that draws nothing and moves nothing.
+ It counts from inside the 1px border, so even with the smallest heading line (26.4px) a finger gets 44.4px. The areas do not
+ widen, so no button takes its neighbor's taps; above the switch is empty page, and below it the help line, which is plain text. */
+@media(min-width:761px) and (pointer:coarse){
+ .hb-watch:has(> .hb-modes) > .hb-modes button{position:relative}
+ .hb-watch:has(> .hb-modes) > .hb-modes button::after{content:"";position:absolute;inset:-10px 0}
}
/* Up to 760px the switch has a row of its own above the stage, its three buttons sharing it equally (.seg.hb-modes outranks the
.seg button rule for phones further down) */
@@ -288,7 +293,7 @@ textarea.hb-text{min-height:88px;padding:10px 12px;resize:vertical}
.hb-page h1{font-size:44px}
.hb-lede{font-size:17px}
.hb-step-head h2{font-size:22px}
- .hb-watch{gap:12px}
+ .hb-watch{--hb-watch-gap:12px}
.hb-page .stage{height:var(--hb-stage-h,clamp(260px,calc(100vh - 330px),440px));height:var(--hb-stage-h,clamp(260px,calc(100svh - 330px),440px))}
/* A stage that grows with its text gets the same shorter minimum */
.hb-page .stage.hb-grow{min-height:clamp(260px,calc(100vh - 330px),440px);min-height:clamp(260px,calc(100svh - 330px),440px)}
diff --git a/tests/pages.test.js b/tests/pages.test.js
index 83a1a3a3..a56982a1 100644
--- a/tests/pages.test.js
+++ b/tests/pages.test.js
@@ -696,12 +696,14 @@ test('from 761px the help line runs under the heading and the switch, as wide as
// its meaning for screen readers. The heading row is no taller than the heading line, so the stage and the player bar stay where
// they are on a page without the switch: the switch is stretched to that line (from 761px its buttons drop the 44px minimum they
// keep up to 760px), the number spans both rows (it reaches into the help line's row there too), and the help line is pulled up
- // by the gap between the step's rows less its own 4px, with the short laptop screens' smaller gap too. The values are read from
- // the rules they follow, so a change to one of those fails here. Every rule from 761px is for a Watch step that has the switch, so
- // a page without it is drawn as before.
+ // by the gap between the step's rows less its own 4px. That gap is set in one place, the custom property --hb-watch-gap (12px on
+ // short laptop screens), and the pull reads it, so the two cannot drift apart. With a coarse pointer (a phone held sideways, a
+ // tablet) each mode button's tap area reaches 10px above and below it, an empty ::after that moves nothing, so even with the
+ // smallest heading line a finger gets 44px. The values are read from the rules they follow, so a change to one of those fails
+ // here. Every rule from 761px is for a Watch step that has the switch, so a page without it is drawn as before.
const bare = read(path.join(ROOT, 'assets', 'css', 'demo-page.css')).replace(/\/\*[\s\S]*?\*\//g, '');
const wide = blockOf(bare, '@media(min-width:761px){');
- const shortWide = blockOf(bare, '@media(min-width:761px) and (max-height:760px){');
+ const coarse = blockOf(bare, '@media(min-width:761px) and (pointer:coarse){');
const shortLaptop = blockOf(bare, '@media(min-width:601px) and (max-height:760px){');
const outside = bare.replace(/@media[^{]*\{(?:[^{}]*\{[^{}]*\})*[^{}]*\}/g, ''); // the rules outside every @media block
// The first px value of a property in the one rule written for exactly this selector
@@ -710,20 +712,6 @@ test('from 761px the help line runs under the heading and the switch, as wide as
assert.equal(found.length, 1, `one ${selector} rule sets ${prop}`);
return Number(found[0].body.match(new RegExp(`(?:^|;)\\s*${prop}:\\s*(-?[\\d.]+)px`))[1]);
};
- const indent = px(outside, '.hb-num', 'width') + px(outside, '.hb-step-head', 'gap');
- const own = px(outside, '.hb-step-head p', 'margin');
- const pull = own - px(outside, '.hb-watch', 'gap');
- const shortPull = own - px(shortLaptop, '.hb-watch', 'gap');
- const W = '.hb-watch:has(> .hb-modes)';
- for (const [what, text] of [
- ['the heading box and the box inside it give way', `${W} > .hb-step-head,${W} > .hb-step-head > div{display:contents}`],
- ['the number is in the first column over the heading row and the help line row, at the top', `${W} > .hb-step-head > .hb-num{grid-row:1/span 2;grid-column:1;align-self:start}`],
- [`the heading is in the first row up to the switch's column, ${indent}px in`, `${W} > .hb-step-head > div > h2{grid-row:1;grid-column:1/-2;margin-left:${indent}px}`],
- [`the help line is in the second row across every column, ${indent}px in, pulled up ${-pull}px`, `${W} > .hb-step-head > div > p{grid-row:2;grid-column:1/-1;margin:${pull}px 0 0 ${indent}px}`],
- ['the switch is in the heading row, stretched to the heading line', `${W} > .hb-modes{grid-row:1;grid-column:2;flex-wrap:nowrap;align-self:stretch}`],
- ['its buttons drop the 44px minimum', `${W} > .hb-modes button{min-height:0}`]
- ]) assert.ok(wide.includes(text), `from 761px: ${what}`);
- assert.ok(shortWide.includes(`${W} > .hb-step-head > div > p{margin-top:${shortPull}px}`), `on a short laptop screen the help line is pulled up ${-shortPull}px`);
// The selectors of a selector list (commas inside brackets, as in :has(a, b), do not split it)
const selectorsOf = list => {
const out = [];
@@ -735,11 +723,39 @@ test('from 761px the help line runs under the heading and the switch, as wide as
}
return [...out, list.slice(from).trim()];
};
+ const indent = px(outside, '.hb-num', 'width') + px(outside, '.hb-step-head', 'gap');
+ const own = px(outside, '.hb-step-head p', 'margin');
+ const W = '.hb-watch:has(> .hb-modes)';
+ assert.ok(outside.includes('.hb-watch{--hb-watch-gap:16px;gap:var(--hb-watch-gap)}'), 'the Watch step\'s gap is --hb-watch-gap, 16px');
+ assert.ok(shortLaptop.includes('.hb-watch{--hb-watch-gap:12px}'), 'on a short laptop screen --hb-watch-gap is 12px');
+ for (const rule of cssRules(bare).filter(r => selectorsOf(r.selector).includes('.hb-watch'))) {
+ assert.ok(!/(^|;)\s*(row-)?gap:\s*(?!var\(--hb-watch-gap\))/.test(rule.body), `the Watch step's gap is set only through --hb-watch-gap: .hb-watch{${rule.body}}`);
+ }
+ for (const [what, text] of [
+ ['the heading box and the box inside it give way', `${W} > .hb-step-head,${W} > .hb-step-head > div{display:contents}`],
+ ['the number is in the first column over the heading row and the help line row, at the top', `${W} > .hb-step-head > .hb-num{grid-row:1/span 2;grid-column:1;align-self:start}`],
+ [`the heading is in the first row up to the switch's column, ${indent}px in`, `${W} > .hb-step-head > div > h2{grid-row:1;grid-column:1/-2;margin-left:${indent}px}`],
+ [`the help line is in the second row across every column, ${indent}px in, pulled up by the step's gap less its own ${own}px`,
+ `${W} > .hb-step-head > div > p{grid-row:2;grid-column:1/-1;margin:calc(${own}px - var(--hb-watch-gap)) 0 0 ${indent}px}`],
+ ['the switch is in the heading row, stretched to the heading line', `${W} > .hb-modes{grid-row:1;grid-column:2;flex-wrap:nowrap;align-self:stretch}`],
+ ['its buttons drop the 44px minimum', `${W} > .hb-modes button{min-height:0}`]
+ ]) assert.ok(wide.includes(text), `from 761px: ${what}`);
+ assert.ok(!bare.includes('@media(min-width:761px) and (max-height:760px)'), 'short laptop screens need no pull of their own: --hb-watch-gap carries their gap');
+ for (const [what, text] of [
+ ['a mode button holds its tap area', `${W} > .hb-modes button{position:relative}`],
+ ['the tap area reaches 10px above and below the button, and no wider', `${W} > .hb-modes button::after{content:"";position:absolute;inset:-10px 0}`]
+ ]) assert.ok(coarse.includes(text), `from 761px with a coarse pointer: ${what}`);
+ // The tap area counts from inside the button's border: the smallest heading line (the heading's smallest font size, everywhere or
+ // on a short laptop screen, times its line height) less the two borders, plus 10px above and 10px below.
+ const [, least, lineHeight] = cssRules(outside).find(r => r.selector === '.hb-step-head h2').body.match(/font:\s*\d+\s+clamp\(([\d.]+)px,[^)]*\)\/([\d.]+)/);
+ const line = Math.min(Number(least), px(shortLaptop, '.hb-step-head h2', 'font-size')) * Number(lineHeight);
+ const tap = line - 2 * px(outside, '.hb-page .seg button', 'border') + 2 * 10;
+ assert.ok(tap >= 44, `with the smallest heading line (${line}px) a mode button's tap area is ${tap}px, under 44px`);
const contents = cssRules(bare).filter(r => /(^|;)\s*display:\s*contents\s*(;|$)/.test(r.body)).flatMap(r => selectorsOf(r.selector));
assert.deepEqual(contents, [`${W} > .hb-step-head`, `${W} > .hb-step-head > div`], 'only the two plain boxes give way');
assert.equal(count(bare, '.hb-modes button{min-height:0}'), 1, 'only from 761px do the mode buttons drop the 44px minimum');
assert.equal(px(outside, '.hb-page .seg button', 'min-height'), 44, 'up to 760px the mode buttons keep the 44px minimum of choice buttons');
- for (const css of [wide, shortWide]) {
+ for (const css of [wide, coarse]) {
for (const rule of cssRules(css)) for (const sel of selectorsOf(rule.selector)) assert.ok(sel.startsWith(W), `for a Watch step with the switch: ${sel}`);
}
});