1. 程式人生 > >HTML——左側邊欄佈局

HTML——左側邊欄佈局


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>上中下佈局</title>
		<style type="text/css">
			body{
				background: #42413C ;
				margin: 0;/*消除body中的留白*/
				padding: 0;
				text-align: center;
			}
			
			.container{
				width: 778px;
				background: #FFF;
				margin: 0 auto;/*側邊的自動值與寬度結合使用,可以將佈局居中對齊*/
				text-align: left;
			}
			
			.header{
				padding: 10px 0;
				background: #ADB96E;
			}
			
			.sidebar{
				float: left;/*側邊欄居左,改為right可令側邊欄居右*/
				width: 200px;
				background: #a4f;
			}
			
			.maincontent{
				width: 570px;
				background: #eee;
			}
			
			.footer{
				clear: both;/*清除前後的浮動元素,使頁尾顯示在其下方*/
				position: relative;/*修改IE瀏覽器中clear無效的bug*/
				padding: 10px 0;
				background: #CCC49F;
			}
		</style>
	</head>
	<body>
		<div class="container">
			<div class="header">
				<h1>網頁頭部</h1>
			</div>
			
			<div class="content">
				<div class="sidebar">
					<h1>側邊欄</h1>
					<h1>側邊欄</h1>
					<h1>側邊欄</h1>
				</div>
				<div class="maincontent">
					<h1>網頁正文</h1>
					<h1>網頁正文</h1>
					<h1>網頁正文</h1>
					<h1>網頁正文</h1>
					<h1>網頁正文</h1>
					<h1>網頁正文</h1>
				</div>
			</div>
			<div class="footer">
				<h1>腳註</h1>
			</div>
		</div>
	</body>
</html>