博客列表 >三列网站双飞翼和圣杯布局方式总结--2018年3月28日01时15分

三列网站双飞翼和圣杯布局方式总结--2018年3月28日01时15分

银河的博客
银河的博客原创
2018年03月28日 01:37:57664浏览

1、三列网站双飞翼布局实现的代码:

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>双飞翼网站布局</title>
	<style>
		/*设定头部和底部相同的属性(宽度、高度、背景颜色)*/
		.header,.footer{
			width:100%;
			height:60px;
			background-color:#999;
			
		}
		/*设定头部和底部块内元素相同的属性(宽度、高度、背景颜色,水平和垂直居中)*/
		.content{
			width: 960px;
			height:100%;
			background-color: #666;
			margin:0 auto;
			text-align: center;
			line-height: 60px;
		
		}
		/*设定中间部分的父级属性(宽度、高度、背景颜色,水平和垂直居中和定位属性)*/
		.contaienr{
			width:960px;
			height: 600px;
			background-color:#DFC7EB; 
			margin:0 auto;
			position:relative;

		}
		/*设定左边部分的属性(宽度、高度、背景颜色,块内元素水平和垂直居中、绝对定位属性)*/
		.left{
			width:200px;
			height: 100%;
			background-color: #8BC7EB;
			position: absolute;
			top:0;
			left:0;
			text-align: center;
			line-height: 600px;
		}
		
		/*设定右边部分的属性(宽度、高度、背景颜色,块内元素水平和垂直居中、绝对定位属性)*/
		.right{
			width:200px;
			height: 100%;
			background-color: #B9EDA1;
			position: absolute;
			top:0;
			right:0;
			text-align: center;
			line-height: 600px;
		}
		
		/*设定中间主体部分的属性(宽度、高度、背景颜色,块内元素水平和垂直居中)*/
		.main{
			width:960px;
			height: 100%;
			background-color: #F5967A;
			text-align: center;
			line-height: 600px;
		}			


	</style>
</head>
<body>
	<div class="header">
		<div class="content">头部</div>
	</div>
	<div class="contaienr">
		<div class="left">左</div>
		<div class=main>中</div>
		<div class="right">右</div>
	</div>
	<div class="footer">
		<div class="content">底部</div>
	</div>
</body>
</html>

运行实例 »

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

运行结果如下:

327.png

此布局方法说明:

中间主体部分要用一个盒子即父级contaienr包起来,并对它进行相对定位,然后子元素中用绝对定位。


2、圣杯式网站布局代码:

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>三列圣杯网站布局</title>
	<style>
		/*设定头部和底部相同的属性(宽度、高度、背景颜色)*/
		.header,.footer{
			width:100%;
			height:60px;
			background-color:#999;
			
		}
		/*清除底部浮动*/
		.footer{
			clear:both;
		}
		/*设定头部和底部块内元素相同的属性(宽度、高度、背景颜色、居中)*/
		.content{
			width: 960px;
			height:100%;
			background-color: #666;
			margin:0 auto;
			text-align: center;
		
		}
		/*设定中间部分的父级属性(宽度、高度、背景颜色,居中、左右边距)*/
		.contaienr{
			width:560px;
			background-color:#DFC7EB; 
			margin:0 auto;
			padding:0 200px;
			

		}
		/*设定中间部分的属性(宽度、高度、背景颜色、向左浮动)*/
		.main{
			width: 100%;
			height: 600px;
			background-color: #F5967A;
			float:left;
		}
		/*设定左边部分的属性(宽度、高度、背景颜色、向左浮动、相对定位)*/
		.left{
			width: 200px;
			height: 600px;
			background-color: #8BC7EB;
			float:left;
			margin-left: -100%;
			position: relative;
			left:-200px;
		}
		
		/*设定右边部分的属性(宽度、高度、背景颜色、向左浮动、相对定位)*/
		.right{
			width: 200px;
			height: 600px;
			background-color:  #B9EDA1;
			float:left;
			margin-left: -200px;
			position: relative;
			right:-200px;
		}
		
		
	</style>
</head>
<body>
	<div class="header">
		<div class="content">头部</div>
	</div>
	<div class="contaienr">
		<div class=main>中</div>
		<div class="left">左</div>
		<div class="right">右</div>
	</div>
	<div class="footer">
		<div class="content">底部</div>
	</div>
</body>
</html>

运行实例 »

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

运行结果如下:

3272.png


此方法和前面说的方法实现了一样的布局效果,只是些方法中用到了浮动,只需将它们分别进行浮动和定位即可实现,要注意的是,必须要对底部清除浮动,否则会错位。中间部分必须先定位


手抄代码:

327.png

3272.png

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