From 5b18b0398889d4fd8cb292b9864580b4a946bf78 Mon Sep 17 00:00:00 2001 From: Timothy Kim Date: Fri, 10 Jul 2026 15:26:12 -0400 Subject: [PATCH] align equal signs with subgrid --- static/factoring.html | 61 +++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/static/factoring.html b/static/factoring.html index 9a7a360..345628e 100644 --- a/static/factoring.html +++ b/static/factoring.html @@ -88,15 +88,26 @@ .problems-grid { display: grid; - grid-template-columns: repeat(2, 1fr); + grid-template-columns: 1fr 1fr; gap: 8px 40px; + align-items: start; + } + + /* Each column defines the shared [num][lhs][=][rhs] tracks; + problems subgrid onto them so every "=" lines up in that column. */ + .prob-col { + display: grid; + grid-template-columns: auto auto max-content 1fr; + column-gap: 6px; + row-gap: 8px; + align-content: start; } .problem { display: grid; - grid-template-columns: 22px 4.4em max-content auto; + grid-column: 1 / -1; + grid-template-columns: subgrid; align-items: baseline; - column-gap: 6px; font-size: 1.2rem; font-weight: 700; padding: 7px 4px; @@ -219,36 +230,40 @@ function genUnique(n) { return out; } +function probRow(idx, lhs, rhs) { + return `
${idx}.` + + `${lhs}=` + + `${rhs}
`; +} + +// Split rows into two subgrid columns (left = first half, read top-to-bottom). +function twoCols(rows) { + const half = Math.ceil(rows.length / 2); + return `
${rows.slice(0, half).join('')}
` + + `
${rows.slice(half).join('')}
`; +} + function renderProblems() { + const L = ''; + // Part I - Factor: given a + b, write the factored form - const partA = genUnique(PER_PART).map((t, i) => - `
${i+1}.` + - `${t.a} + ${t.b}=` + - `( + )` + - `
` - ).join(''); + const rowsA = genUnique(PER_PART).map((t, i) => + probRow(i + 1, `${t.a} + ${t.b}`, `${L}(${L} + ${L})`)); // Part II - Expand: given x(y + z), write the sum - const partB = genUnique(PER_PART).map((t, i) => - `
${i+1}.` + - `${t.x}(${t.y} + ${t.z})=` + - ` + ` + - `
` - ).join(''); + const rowsB = genUnique(PER_PART).map((t, i) => + probRow(i + 1, `${t.x}(${t.y} + ${t.z})`, `${L} + ${L}`)); // Part III - Find the common factor: fill the box - const partC = genUnique(PER_PART).map((t, i) => - `
${i+1}.` + - `${t.a} + ${t.b}=` + - `(${t.y} + ${t.z})
` - ).join(''); + const rowsC = genUnique(PER_PART).map((t, i) => + probRow(i + 1, `${t.a} + ${t.b}`, `(${t.y} + ${t.z})`)); return ` -

Part I. Factor out the common factor.

${partA}
+

Part I. Factor out the common factor.

${twoCols(rowsA)}

-

Part II. Multiply it back out.

${partB}
+

Part II. Multiply it back out.

${twoCols(rowsB)}

-

Part III. Fill in the common factor.

${partC}
+

Part III. Fill in the common factor.

${twoCols(rowsC)}
`; }