通欄(Full-width Bar)指橫跨整個視窗寬度的版面區塊(如頂部導覽、底部版權),內容區再置中限制寬度。以下提供可直接套用的完整架構範例。
width: 100% 撐滿視窗,背景色/圖延伸全幅。width: 980px; margin: 0 auto; 置中承載內容。box-sizing: border-box 避免 padding 撐破寬度。<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>通欄版面範例</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
ul { list-style: none; }
img { border: none; vertical-align: top; }
a { text-decoration: none; color: #fff; }
a:hover { text-decoration: underline; }
/* 通欄結構 */
#header { width: 100%; background: #eee; }
#menu_bg { width: 100%; background: pink; height: 50px; }
#menu { width: 980px; margin: 0 auto; }
#menu li { width: 101px; float: left; }
#menu a { display: block; width: 100px; height: 48px; line-height: 48px; text-align: center; background: black; border-bottom: 2px solid black; }
#menu a:hover { border-bottom-color: pink; }
#wrap { width: 980px; height: 500px; margin: 0 auto; background: green; }
#footer_bg { width: 100%; background: pink; height: 50px; }
#footer { width: 980px; margin: 0 auto; }
.friend_links li { display: inline; margin-right: 15px; }
</style>
</head>
<body>
<div id="header">
<div id="logo">Logo 區塊</div>
<div id="menu_bg">
<div id="menu">
<ul>
<li class="current"><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
<li><a href="#">Price</a></li>
</ul>
</div>
</div>
</div>
<div id="wrap">主內容區</div>
<div id="footer_bg">
<div id="footer">
<p class="copyright">© 2024 公司名稱</p>
<ul class="friend_links">
<li>百度</li><li>Google</li><li>有道</li><li>騰訊</li>
</ul>
</div>
</div>
</body>
</html>
#menu li 寬度 101px × 4 = 404px,配合 #menu 980px 仍有餘裕,實務上建議用 flex 平均分配。border-bottom 做為 hover 指示器,比改變背景色更輕量。display: inline 水平排列,簡潔高效。/* Flexbox 版通欄選單 */
#menu { display: flex; justify-content: center; }
#menu li { flex: 1; max-width: 120px; }
#menu a { display: flex; align-items: center; justify-content: center; }
Flexbox 免清除浮動、自適應項目數、垂直置中原生支援,強烈建議新專案採用。