屏幕尺寸譜系從 320px(iPhone)延伸至 2560px+(大屏顯示器),固定寬度設計已無法應對多設備瀏覽現實。響應式 Web 設計(RWD)通過彈性網格佈局 + 自適應圖片 + CSS3 Media Queries三大支柱,實現單一代碼庫跨設備優雅適配。本文以完整實例演示從固定寬度向響應式佈局的重構全過程。
拖拽瀏覽器窗口觀察佈局自適應變化:


<div id="pagewrap">
<header id="header">
<hgroup>
<h1 id="site-logo">Demo</h1>
<h2 id="site-description">Site Description</h2>
</hgroup>
<nav>
<ul id="main-nav"><li><a href="#">Home</a></li></ul>
</nav>
<form id="searchform"><input type="search"></form>
</header>
<div id="content"><article class="post">blog post</article></div>
<aside id="sidebar"><section class="widget">widget</section></aside>
<footer id="footer">footer</footer>
</div>
<!--[if lt IE 9]>
<script src="https://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
/* HTML5 元素塊級化 */
article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section { display: block; }
/* 預設固定佈局 */
#pagewrap { width: 980px; margin: 0 auto; }
#header { height: 160px; }
#content { width: 600px; float: left; }
#sidebar { width: 280px; float: right; }
#footer { clear: both; }
<!--[if lt IE 9]>
<script src="https://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script>
<![endif]-->
@media screen and (max-width: 980px) {
#pagewrap { width: 95%; }
#content { width: 60%; padding: 3% 4%; }
#sidebar { width: 30%; }
#sidebar .widget { padding: 8% 7%; margin-bottom: 10px; }
}
@media screen and (max-width: 650px) {
#header { height: auto; }
#searchform { position: absolute; top: 5px; right: 0; }
#main-nav, #site-logo, #site-description { position: static; }
#site-logo { margin: 15px 100px 5px 0; }
#content { width: auto; float: none; }
#sidebar { width: 100%; float: none; }
}
min-width 遞增),減少代碼覆蓋、提升維護性img { max-width: 100%; height: auto; } + <picture>/srcset 實現美術導向與分辨率切換<meta name="viewport" content="width=device-width, initial-scale=1">Tisa、Elemin、Suco、iTheme2、Funki、Minblr、Wumblr 等主題均採用 Media Queries 響應式架構。
響應式設計不是技術棧的疊加,而是「內容優先、漸進增強、以用戶體驗為度量衡」的設計哲學落地。掌握 Media Queries 只是起點,真正的挑戰在於在無限設備組合中,用有限代碼交付一致優質的核心體驗。