This is just a placeholder.
段落1
段落2
段落3
段落4
段落5
段落6
# Day 60:前端切版重構技術筆記 **Published by:** [雞蛋糕的前端修煉屋](https://paragraph.com/@gcake/) **Published on:** 2026-02-13 **URL:** https://paragraph.com/@gcake/day-60 ## Content 目錄Part 1: CSS 命名系統Part 2: 重構過程與問題解決Part 1: CSS 命名系統業界常見的 CSS 命名方式1. BEM (Block Element Modifier)核心概念:用「區塊-元素-修飾符」三層結構命名,讓 class 名稱本身就能表達元素的身份和關係。 frontendmentor 命名規則:.block → 獨立元件 .block__element → 元件內的子元素 .block--modifier → 元件的變化版本 實例:
內容
Content
ZERO TYPE
ZERO TYPE
+
分隔段落 HTML(錯誤):
段落1
段落2
段落3
,不是 1 個
加 5 個 段落1 段落2 段落3 段落4 段落5 段落6
無障礙問題:螢幕閱讀器會把整段當成「一個段落」無法單獨控制樣式:無法給「第一段加粗」、「第三段換顏色」SEO 不友善:搜尋引擎無法正確解析段落結構正確寫法:This is just a placeholder.
應該用於詩歌、地址等「同段落內的換行」,不該用於分隔不同段落column-count 應該在父容器,讓整篇文章分欄,而非每個段落內部分欄問題 4: Header 視窗縮小時會換行症狀:視窗寬度稍微減少時,Nav 會被推到第二行。 原因分析:視窗最小寬度 = 1200px(body min-width) Header 可用寬度 = 1200px - 150px(左padding)- 50px(右padding)= 1000px Logo 區佔用 = 60px + 120px(margin-right)= 180px Nav 區需要 = 5個項目 × 150px(間距)+ 文字寬度(約350px)= 950px 總共需要 = 180px + 950px = 1130px 可用寬度 = 1000px 1130px > 1000px → 放不下! 解法 1:加大視窗body { min-width: 1400px; /* 從 1200px 改成 1400px */ } /* 新的可用寬度 = 1400px - 200px = 1200px > 1130px ✅ */ 解法 2:減少間距.header__nav-item { margin-right: 100px; /* 從 150px 改成 100px */ } /* Nav 寬度 = 4個 × 100px + 350px = 750px */ /* 總需要 = 180px + 750px = 930px < 1000px ✅ */ 學習重點:inline-block 元素換行時,整個元素會掉到下一行(不是內容換行)寬度計算公式:可用寬度 = 視窗寬 - 左右 padding,需要寬度 = 元素1 + 間距 + 元素2目前階段需要「精確計算每個數值」,未來學 Flexbox 後瀏覽器會自動處理問題 5: 圖片底部有空隙症狀:inline 圖片容器下方有約 3-4px 的空隙。 原因:瀏覽器預設給 inline 元素留空間放英文小寫字母的下半部(如 g、y、p 的下半部)。 developer.mozilla 解法:.header__logo-img, .hero__img { vertical-align: bottom; /* 對齊底線,消除空隙 */ } 學習重點:inline 或 inline-block 的圖片都要加 vertical-align: bottom 或改成 display: block。Box Model 寬度計算原理基本公式可用寬度 = 視窗寬度 - 左右 padding 需要寬度 = 元素1寬度 + 間距 + 元素2寬度 如果 需要寬度 > 可用寬度,第二個元素會掉到下一行。實際範例Header 計算:視窗寬度 = 1200px Header padding = 150px(左)+ 50px(右)= 200px Header 可用寬度 = 1200px - 200px = 1000px Logo 寬度 = 60px + 120px(margin-right)= 180px Nav 寬度 = (5個項目 × 150px) + 文字寬度(約350px)= 950px 總共需要 = 180px + 950px = 1130px 1130px > 1000px → Nav 會換行 ❌ 解決方法:加大可用寬度:min-width: 1400px → 可用寬度變 1200px減少需要寬度:margin-right: 100px → Nav 寬度變 750pxinline-block 的間隙問題問題:HTML 的換行會被瀏覽器當成「空白字符」,導致 inline-block 元素之間有約 4px 間隙。 developer.mozilla HTML:
ZERO TYPE
You can remove any link to our website from this website template, you're free to use this website template without linking back to us.
Don't worry it's for free.
You can remove any link to our website from this website template, you're free to use this website template without linking back to us.
This is just a place holder, so you can see what the site would look like.
You can remove any link to our website from this website template, you're free to use this website template without linking back to us. This is just a place holder, so you can see what the site would look like.
You can remove any link to our website from this website template, you're free to use this website template without linking back to us.
This is just a place holder, so you can see what the site would look like.
You can remove any link to our website from this website template, you're free to use this website template without linking back to us. This is just a place holder, so you can see what the site would look like.
而非
,語意正確且對 SEO/無障礙友善4. 未來的改進方向Flexbox:自動分配空間,不用計算寬度,自動垂直置中Grid:用比例分配空間,適合複雜二維佈局目前的痛點都會被解決:魔術數字、換行問題、對齊困難參考資源官方文件MDN CSS 組織指南:介紹 OOCSS、BEM、SMACSS developer.mozillaMDN CSS Specificity:權重計算規則 developer.mozillaW3C HTML5 規範:段落與換行的正確用法社群資源CSS Specificity Calculator:https://specificity.keegan.st/ (線上計算工具)BEM 官方文件:http://getbem.comAirbnb JavaScript Style Guide:包含 CSS 寫作規範延伸閱讀BEM vs 巢狀選擇器的效能與權重分析 zoochaTailwind CSS 與 BEM 混用最佳實踐 wearecogworksCSS 架構方法論比較 sitepoint
## Publication Information
- [雞蛋糕的前端修煉屋](https://paragraph.com/@gcake/): Publication homepage
- [All Posts](https://paragraph.com/@gcake/): More posts from this publication
- [RSS Feed](https://api.paragraph.com/blogs/rss/@gcake): Subscribe to updates