LESSON-08 · TOPIC 02

區塊間距節奏

能用有限 spacing scale 管理 section 間距,讓相同層級只出現可預測的節奏值。

code-edit首頁 CSS 組裝與 landmarks|區塊間距節奏本頁只練一個責任

本頁只練什麼

能用有限 spacing scale 管理 section 間距,讓相同層級只出現可預測的節奏值。

每個區塊各寫任意 margin 會逐頁漂移;token 化節奏能讓新增內容仍維持一致層級與密度。

要修改的檔案:files/starter/style.css

定位:在 Computed 讀第二個 section 的 margin-block-start,先記錄目前是否屬於 spacing scale。|依 starter-2 定位,只修改「區塊間距節奏」的責任。

任務情境

先結果,再原理;完成後要能說出自己看見的證據。

現在的問題

首頁四個 section 各自由不同人加入,垂直留白看似相近卻沒有一致規則。

起始狀態:第二個 section 使用任意 13px margin-block-start。

完成後要看到

runtime 的 margin-block-start 由 13px 變 32px;其他相同層級 section 使用同一 token。

驗收證據:runtime before=13px、after=32px、property=margin-block-start

何時會用到

首頁 hero、服務、案例、CTA 等同層區塊需要一致分隔時。

常見混淆:spacing rhythm 不是所有距離都一樣;不同結構層級可使用不同 token,但每層用途要一致。

觀念與最小範例

這段程式是理解起點,不是要你直接跳過 Starter。

區塊間距節奏 Section spacing rhythm

間距像音樂拍子,選少量固定拍點反覆使用,比每次憑感覺留白更整齊。

正式說法:A spacing scale is a constrained set of design token values used according to structural relationships;margin-block expresses vertical rhythm in logical flow direction。

:root{--space-sm:.5rem;--space-md:1rem;--space-lg:2rem}.page-section+.page-section{margin-block-start:var(--space-lg)}

三步完成本主題

每一步都留下可觀察結果;如果沒看到,先看「卡住先查」。

  1. Step 1|先看見目前缺口,不急著貼答案。

    檔案:files/starter/style.css 定位:在 Computed 讀第二個 section 的 margin-block-start,先記錄目前是否屬於 spacing scale。

    要做:先重新載入 Starter,記錄目前畫面、DOM、Computed、Console 或文件內容。

    預期:能指出「在 Computed 讀第二個 section 的 margin-block-start,先記錄目前是否屬於 spacing scale。」目前的缺口。

    證據:保存 files/starter/style.css 的目前狀態,並指出下一步只會修改哪個檔案責任。

    卡住先查:確認開啟的是 files/starter/style.css,且定位到 在 Computed 讀第二個 section 的 margin-block-start,先記錄目前是否屬於 spacing scale。。

  2. Step 2|只修改本主題的一個責任。

    檔案:files/starter/style.css 定位:在 Computed 讀第二個 section 的 margin-block-start,先記錄目前是否屬於 spacing scale。

    要做:執行實驗替第二個 section 切換 use-spacing-token class,讀取 computed margin-block-start。

    預期:runtime 的 margin-block-start 由 13px 變 32px;其他相同層級 section 使用同一 token。

    證據:runtime before=13px、after=32px、property=margin-block-start

    卡住先查:在 Computed 讀第二個 section 的 margin-block-start,先記錄目前是否屬於 spacing scale。

  3. Step 3|重新載入並以證據驗收,不以『看起來差不多』判定完成。

    檔案:files/starter/style.css 定位:在 Computed 讀第二個 section 的 margin-block-start,先記錄目前是否屬於 spacing scale。

    要做:重新整理頁面,再逐項比對預期結果與 evidence。

    預期:runtime 的 margin-block-start 由 13px 變 32px;其他相同層級 section 使用同一 token。

    證據:runtime before=13px、after=32px、property=margin-block-start

    卡住先查:在 Computed 讀第二個 section 的 margin-block-start,先記錄目前是否屬於 spacing scale。

觀察示範

這個示範只讓你看懂概念,不會替你修改 Starter,也不會自動宣告完成。

區塊間距節奏runtime fixture · read-only demo
本主題示範畫面:
服務
案例

驗收證據

勾選只是學習紀錄;真正完成仍要回到 Starter 的實際結果。

提示 1|方向

先列出目前所有 section 間距,只留下有限尺度。

提示 2|關鍵片段

同層 section 統一使用 --space-lg:2rem。

提示 3|完整解答與原因

完整解答與原因:將任意 13px 改為 var(--space-lg)=32px,讓同層新增區塊仍有可預測節奏。

完成後進入下一階段,或回到入口選下一個 topic。

開始 Starter →回到主題清單