博客列表 >css三列布局-2018年3月28日13时10分

css三列布局-2018年3月28日13时10分

沈斌的博客
沈斌的博客原创
2018年03月28日 13:57:21718浏览

css双飞翼布局,使用了float,margin,中间主体用div wrap包裹,margin left margin right确定主体。

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>bird layout</title>
	<style type="text/css">
		.header,.footer {
			width: 100%;
			height: 60px;
			background-color: lightgrey;
		}
		.content {
			width:1000px; 
			min-height: 100%;
			
			margin: auto;

			text-align: center;
			line-height: 60px;

			background-color: grey;
			
			
		}
		.footer {
			clear: both;
		}

		.container {
			width: 1000px;
			margin: auto;
			background-color: yellow;
			overflow: hidden;
		}
		
		.wrap {
			width: 100%;
			background: cyan;
			float: left;
		}
		.middle {
			
			min-height: 600px;
			margin: 0 200px;
			
			border: 1px solid black;
			
			

		}
		.left{
			width: 200px;
			min-height: 600px;
			float: left;
			background-color: lightblue;

			margin-left:-100%;
		}
		.right {
			width: 200px;
			min-height: 600px;
			float: left;
			background-color: lightgreen;

			margin-left: -200px;
		}
	</style>
</head>
<body>
	<div class="header">
		<div class="content">网站顶部</div>
	</div>
	<div class="container">
		<div class="wrap">
			<div class="middle">中部</div>
		</div>
		
		<div class="left">左边</div>
		<div class="right">右边</div>
	</div>
	<div class="footer">
		<div class="content">网站底部</div>
	</div>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例


css圣杯布局,使用了float,margin,使用绝对定位确定中间主体。

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>cup layout</title>
	<style type="text/css">
		.header,.footer {
			width: 100%;
			height: 60px;
			background-color: lightgrey;
		}
		.content {
			width:1000px; 
			min-height: 100%;
			
			margin: auto;

			text-align: center;
			line-height: 60px;

			background-color: grey;
			
			
		}
		.footer {
			clear: both;
		}
		
		.container {
			width: 600px;
			background-color: yellow;
			/*父容器及内部区块水平居中*/
			margin: auto;
			overflow: hidden;

			padding: 0 200px;

		}

		.container .middle {
			min-height: 650px;
			width: 100%;
			float: left;
			background-color: lightgreen;
		}

		.container .left {
			width: 200px;
			min-height: 650px;
			float: left;
			background-color: lightskyblue;
			margin-left: -100%;

			position: relative;
			left: -200px;
		}

		.container .right {
			width: 200px;
			min-height: 650px;
			float: left;
			background-color: wheat;
			margin-left: -200px;

			position: relative;
			right: -200px;
		}
	</style>
</head>
<body>
	<div class="header">
		<div class="content">网站顶部</div>
	</div>
	<div class="container">
		<div class="middle">中部</div>
		
		<div class="left">左边</div>
		<div class="right">右边</div>
	</div>
	<div class="footer">
		<div class="content">网站底部</div>
	</div>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

总结:

双飞翼布局主体多了一层div标签,圣杯布局多了css属性设置。两种布局都使用了float属性,margin-left属性。

双飞翼布局,圣杯布局容器container设置的width不同,导致后面处理main也不同。



手抄

layout1.JPG

layout2.JPG

cup.png

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议