圣杯布局与双飞翼布局

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>双飞翼布局</title>
	<style>
		*{
			margin: 0;
			padding: 0;
		}
		.container{
			height: 300px;
			background-color: pink;
			min-width: 480px;
		}
		.left,.right{
			width: 200px;
			height: 300px;
			background-color: blue;
			float: left;
		}
		.main{
			width: 100%;
			height: 300px;
			background-color: red;
			float: left;
		}
		.left{
			margin-left: -100%;
		}
		.right{
			margin-left: -200px;
		}
		.main_w{
			margin:0 200px;
		}

	</style>
</head>
<body>
	<div class="container">
		<div class="main">
			<div class="main_w">中间栏</div>
		</div>
		<div class="left">左边栏</div>
		<div class="right">右边栏</div>
	</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>圣杯布局</title>
	<style>
		*{
			margin: 0;
			padding: 0;
		}
		.container{
			height: 300px;
			background-color: pink;
			min-width: 480px;
			padding:0 200px;
		}
		.left,.right{
			width: 200px;
			height: 300px;
			background-color: blue;
			float: left;
		}
		.main{
			width: 100%;
			height: 300px;
			background-color: red;
			float: left;
		}
		.left{
			position: relative;
			left: -200px;
			margin-left: -100%; 
		}
		.right{
			position: relative;
			right: -200px;
			margin-left: -200px; 			
		}

	</style>
</head>
<body>
	<div class="container">
		<div class="main">
			   中间栏
		</div>
		<div class="left">左边栏</div>
		<div class="right">右边栏</div>
	</div>
</body>
</html>
使用margin可以强行移位,浮动层可以触及padding区域,也可以触及浮动区域

发表评论

邮箱地址不会被公开。 必填项已用*标注