商用網站架設實務

LESSON-08 · checkpoint

CSS 基礎:首頁整合

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

Starter2 個小成果
Checkpoint一個核心缺口
Solution3 個差異

開始前確認

這一頁的結果:先觀察 service.html 的唯一 404

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

會用到的檔案:index.htmlstyle.cssmain.jsservices.html

本堂焦點:整合共用容器、Hero、服務摘要與 CTA 成為首頁

照這個順序做

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

CHECKPOINT-1

讓學生練習從瀏覽器的失敗證據回到 HTML 的 href,而不是盲目重寫整頁。

目的

讓學生練習從瀏覽器的失敗證據回到 HTML 的 href,而不是盲目重寫整頁。

修改檔案

index.html

程式碼位置

.primary-button[href]

現在要做:請在 index.html 的「.primary-button[href]」位置完成:只替換主要 CTA 的 href,將 service.html 修正為 services.html

貼上位置:index.html:.primary-button[href] 區塊,先保留同一檔案的其他內容。

<a class="primary-button" href="service.html">查看服務內容</a>

預期結果:修正前 Networkservice.html 404;修正後點擊 CTA 能開啟 services.html

驗收證據:Network 先看到 service.html 404,再看到 services.html 成功載入;兩個頁面的 Console 都沒有 TypeError。

卡住時先看這裡

常見錯誤:把正確連結再追加到既有連結後面,或直接重貼整個首頁,讓學生看不到替換前後差異。

第一個檢查:先點 CTA 並在 Network 找到失敗請求,再回 Elements 或 Sources 搜尋 href 的實際字串。

階段檔案

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

開啟 checkpoint 的可執行入口

index.html首頁入口:建立唯一 h1、main、Hero、服務摘要與服務頁 CTA

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

<!doctype html>
<html lang="zh-Hant">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>沐光工作室|首頁</title>
  <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Crect width='16' height='16' rx='4' fill='%230f4c5c'/%3E%3C/svg%3E" type="image/svg+xml">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <header class="site-header">
    <a class="brand" href="index.html">沐光工作室</a>
    <nav aria-label="主要導覽"><a href="services.html">服務方案</a></nav>
  </header>
  <main class="page-shell">
    <section class="hero" aria-labelledby="hero-title">
      <p class="eyebrow">LESSON-08 · 首頁整合</p>
      <h1 id="hero-title">沐光工作室:讓空間回到生活</h1>
      <p>用清楚的頁面區塊,讓訪客快速理解我們能提供什麼。</p>
      <!-- CHECKPOINT-1:CTA 故意指向 service.html,請先用 Network 找到 404。 -->
      <a class="primary-button" href="service.html">查看服務內容</a>
    </section>
    <section id="services" class="service-summary" aria-labelledby="services-title">
      <h2 id="services-title">服務摘要</h2>
      <ul class="service-list">
        <li><h3>品牌網站</h3><p>建立可信任的第一印象。</p></li>
        <li><h3>內容整理</h3><p>把複雜資訊變成可閱讀的路徑。</p></li>
        <li><h3>持續優化</h3><p>用觀察與迭代讓體驗越來越好。</p></li>
      </ul>
    </section>
  </main>
  <script src="main.js" defer></script>
</body>
</html>
style.css共用樣式:觀察 page-shell、hero、primary-button、focus 與窄版 media query

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

: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; }
a { color: #16324f; }
.site-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; width: min(100% - 2rem, 760px); margin: 1rem auto 0; }
.site-header nav { display: flex; gap: 1rem; }
.eyebrow { color: #176b87; font-weight: 800; }
a:focus-visible { outline: 3px solid #f1ab2c; outline-offset: 3px; }
.page-shell { width: calc(100% - 2rem); max-width: 760px; margin: 2rem auto; padding: 2rem; border: 1px solid #cbd8e4; border-radius: 20px; background: #fff; }
.hero { padding-block: 3rem 2rem; }
.service-list { list-style: none; margin: 1.5rem 0 0; padding: 0; }
.service-list li { padding: 1rem; border: 1px solid #d8e0ea; border-radius: 14px; }
.service-list li + li { margin-top: 1rem; }
.primary-button { display: inline-block; margin-top: 1rem; padding: .75rem 1rem; border-radius: 999px; background: #16324f; color: #fff; text-decoration: none; }
.primary-button:hover, .primary-button:focus-visible { background: #0b1f33; }
.primary-button:focus-visible, .site-header a:focus-visible { outline: 3px solid #f1ab2c; outline-offset: 3px; }
@media (max-width: 560px) { .site-header { width: calc(100% - 1rem); } .page-shell { width: calc(100% - 1rem); margin-block: 1rem; padding: 1rem; } }
main.js預寫驗收腳本:所有頁面都能安全載入,學生不修改本檔。

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

const status = document.querySelector("#status");
const action = document.querySelector("#action");

console.log("LESSON-08:預寫驗收腳本已載入");

function showResult() {
  if (status) status.textContent = "LESSON-08:首頁整合驗收完成";
  console.log("LESSON-08:首頁整合驗收完成");
}

if (action) action.addEventListener("click", showResult);
services.html服務頁入口:提供 CTA 的真實相對路徑目標,沒有 status/action 也不會造成 JS 錯誤。

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

<!doctype html>
<html lang="zh-Hant">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>服務方案|沐光工作室</title>
  <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Crect width='16' height='16' rx='4' fill='%230f4c5c'/%3E%3C/svg%3E" type="image/svg+xml">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <header class="site-header">
    <a class="brand" href="index.html">沐光工作室</a>
    <nav aria-label="主要導覽"><a href="index.html">回到首頁</a></nav>
  </header>
  <main class="page-shell">
    <p class="eyebrow">LESSON-08 · 服務頁</p>
    <h1>服務方案</h1>
    <section aria-labelledby="services-title">
      <h2 id="services-title">把需求變成可執行的方案</h2>
      <ul class="service-list">
        <li><h3>品牌網站</h3><p>建立可信任的第一印象。</p></li>
        <li><h3>內容整理</h3><p>把複雜資訊變成可閱讀的路徑。</p></li>
        <li><h3>持續優化</h3><p>用觀察與迭代讓體驗越來越好。</p></li>
      </ul>
    </section>
  </main>
  <script src="main.js" defer></script>
</body>
</html>

完成驗收

下一步

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

前往 Solution,逐檔對照差異