自適應設計(RWD)核心:流式網格、彈性圖片、媒體查詢。四步快速將傳統固寬站點轉為多設備友好。
<meta name="viewport" content="width=device-width, initial-scale=1">
告訴瀏覽器:視口寬度 = 設備寬度,不縮放。支援 Chrome/FF/IE9+,IE8 需 respond.js Polyfill。
@media screen and (max-width: 480px) {
#divMain { float: none; width: auto; }
#divSidebar { display: none; }
}
min-width 逐層增強。.container { width: 90%; max-width: 1200px; margin: 0 auto; }
.sidebar { width: 30%; }
.content { width: 65%; }
配合 box-sizing: border-box,百分比佈局自動適配容器。
html { font-size: 100%; } /* 16px 基準 */
body { font-size: 1rem; } /* 16px */
h1 { font-size: 2rem; } /* 32px */
.small { font-size: 0.875rem; } /* 14px */
rem 相對根元素,em 相對父元素,rem 更可控。@media (max-width:480px){ html{font-size:90%;} } 全局縮放。min-height 或 auto。flex-wrap:wrap 或漢堡菜單。img { max-width:100%; height:auto; }。PostCSS (autoprefixer、postcss-pxtorem)、Stylelint、Chrome DevTools Device Toolbar、Responsive Viewer 擴充套件。