<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml" lang="zh-TW" xml:lang="zh-TW">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>三欄式版面</title>
<link rel="stylesheet" type="text/css" href="style.css" media="screen,projection" />
</head>
<body>
<div id="header"><h1>頁首</h1></div>
<div id="container">
<div id="sidebar-left"><h2>左側欄</h2></div>
<div id="main-content"><h2>主內容</h2></div>
<div id="sidebar-right"><h2>右側欄</h2></div>
</div>
<div id="footer"><p>頁尾</p></div>
</body>
</html>
* { box-sizing: border-box; margin: 0; padding: 0; }
#header { width: 100%; height: 120px; background: #0074c8; text-align: center; padding-top: 20px; }
#container { width: 100%; overflow: hidden; /* 清除浮動 */ }
#sidebar-left { width: 33.3%; height: 500px; float: left; background: #ffff99; }
#main-content { width: 33.4%; height: 500px; float: left; background: #ffffcc; border-left: 1px solid #ccc; border-right: 1px solid #ccc; }
#sidebar-right { width: 33.3%; height: 500px; float: left; background: #ffff99; }
#footer { width: 100%; height: 70px; background: #0074c8; text-align: center; padding-top: 20px; clear: both; }
h1,h2,p { color: #333; }
/* Flexbox */
#container { display: flex; }
#sidebar-left { flex: 0 0 33.33%; }
#main-content { flex: 0 0 33.34%; }
#sidebar-right { flex: 0 0 33.33%; }
/* Grid */
#container { display: grid; grid-template-columns: 1fr 1fr 1fr; }
無需浮動、自動等高、響應式輕鬆切換欄數。