商用網站架設實務

LESSON-07 · checkpoint

CSS 基礎:Flexbox

主要結構已經完成,只留下本堂一個核心缺口。先預測,再從指定檔案找出它。 這頁用 可觀察證據anchor 指出下一個動作。

Starter3 個小成果
Checkpoint一個核心缺口
Solution4 個差異

開始前確認

這一頁的結果:入口頁可以開啟

工作方式:先把這一階段複製到自己的工作資料夾,開啟 files/index.html,記下修改前的畫面、DOM、Console 或 Network狀態。

會用到的檔案:index.htmlstyle.cssmain.js

本堂焦點:Flexbox 排列導覽列、頁首與服務卡片

照這個順序做

一次只做一張卡。完成後先重新整理入口,再留下證據,才進入下一張。

CHECKPOINT-1

讓一維排列在可用空間不足時仍能閱讀。

目的

讓一維排列在可用空間不足時仍能閱讀。

修改檔案

style.css

程式碼位置

.service-list flex-wrap

現在要做:請在 style.css 的「.service-list flex-wrap」位置完成:補上 flex-wrap 讓服務卡在窄版換行

貼上位置:style.css:.service-list flex-wrap 區塊,先保留同一檔案的其他內容。

.service-list { flex-wrap: wrap; }

預期結果:390px 下卡片換行且沒有水平捲軸。

驗收證據:390px 畫面與 Computed flex-wrap。

卡住時先看這裡

常見錯誤:固定每張卡寬度超過 viewport

第一個檢查:只看 .service-list 的 flex-wrap 與子卡 width。

階段檔案

完整檔案收在可展開的卡片中;先完成上方微步驟,再用這裡查閱與複製。檔案位置要和目前的相對路徑一致。

開啟 checkpoint 的可執行入口

index.html入口檔案:從這份 HTML 開始觀察本堂主題結果。

這段要貼在哪裡:先在自己的工作資料夾建立同名相對位置,再複製內容。

<!doctype html>
<html lang="zh-Hant">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>CSS 基礎:Flexbox</title>
<link rel="icon" href="../../../assets/favicon.svg" type="image/svg+xml">
<link rel="stylesheet" href="style.css">
</head>
<body>
<header class="site-header"><a class="brand" href="index.html">安心維護</a><span class="single-page-label">本堂單頁練習</span></header>
<main class="page-shell">
<p class="eyebrow">LESSON-07 · 用 Flexbox 排列導覽列、頁首與服務卡片</p>
<h1>CSS 基礎:Flexbox</h1>
<p class="page-description">用 Flexbox 排列導覽列、頁首與服務卡片</p>
<!-- lesson-slot -->
<section class="result-card" aria-labelledby="result-title">
<h2 id="result-title">本堂可觀察結果</h2>
<p id="status" role="status">尚未操作,請依微步驟完成本堂練習。</p>
<button id="action" type="button">執行本堂操作</button>
</section>
</main>
<script src="main.js" defer></script>
</body>
</html>
style.css呈現層:只放本堂實作需要觀察的 CSS 規則。

這段要貼在哪裡:先在自己的工作資料夾建立同名相對位置,再複製內容。

:root { font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans TC", sans-serif; color: #17324d; background: #f5f8fb; }
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; line-height: 1.7; }
.site-header { width: min(100% - 2rem, 920px); margin: 1rem auto 0; padding: .75rem 0; display: flex; justify-content: space-between; gap: 1rem; align-items: center; }
.site-header nav { display: flex; flex-wrap: wrap; gap: .7rem; }
.site-header a { color: #155e75; }
.page-shell { width: min(100% - 2rem, 760px); margin: 2rem auto; padding: 2rem; border: 1px solid #cbd8e4; border-radius: 20px; background: #fff; }
.eyebrow { color: #176b87; font-weight: 800; }
.page-description { color: #52657d; }
.result-card { padding: 1rem; border: 1px solid #d8e0ea; border-radius: 14px; background: #fbfdff; }
button { padding: .65rem .9rem; border: 0; border-radius: 9px; background: #176b87; color: #fff; font: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 3px solid #f1ab2c; outline-offset: 3px; }
.status { min-height: 2rem; color: #17643d; }
.service-list {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
/* CHECKPOINT-1:請在 style.css 的「.service-list flex-wrap」位置完成:補上 flex-wrap 讓服務卡在窄版換行 */
/* 本堂缺口:卡片仍被迫排在同一列,窄版會溢位。 */
@media (max-width: 560px) { .site-header { align-items: flex-start; flex-direction: column; } .page-shell { margin: 1rem auto; padding: 1rem; } h1 { font-size: 1.6rem; } }
main.js行為層:處理本堂操作、狀態與 Console 驗收訊息。

這段要貼在哪裡:先在自己的工作資料夾建立同名相對位置,再複製內容。

const status = document.querySelector("#status, #baseline-status");
const action = document.querySelector("#action, #baseline-action");
function showResult() {
  if (status) status.textContent = "用 Flexbox 排列導覽列、頁首與服務卡片:先完成入口操作,再逐步驗收。";
  console.log("LESSON-07:入口已執行");
}
status.textContent = "flex layout:主軸、對齊與換行已驗證";
console.log("flex layout:主軸、對齊與換行已驗證");
if (action) action.addEventListener("click", showResult);

完成驗收

下一步

Checkpoint 完成後,先說出你修正的原因,再前往 Solution 對照每個檔案差異。

前往 Solution,逐檔對照差異