博主信息
博文 45
粉丝 2
评论 1
访问量 32569
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
css中双飞翼.圣杯布局的总结-2018年3月28号1点03分
哈的博客
原创
747人浏览过

总结:

在css中3列布局是非常重要的,无论在中国网站还在在外国的网站到处都可以看到3列布局的存在,应该非常广泛,在3.27号中为们学习了绝对定位的3列布局。双飞翼3列布局,圣杯3列布局,还有用到很多的以前的知识,学习代码不经可以学习到新的东西,还可以复习到其他以前学过的知识点,因为代码都是重复使用的。在双飞翼中一定要注意给父元素设置宽度,还有要注意的是浮动是脱离文档流的,防止塌陷。给中间的div加一个空壳,防止被撑大

实例
这是双飞翼3列布局,用到了浮动元素:基本思路:
	首先创建一个大盒子,包含着3个元素并设置高度,然后水平居中。
	再创建3个div盒子先设置中间的区块并设置100%的宽度,然后设置左右区块,
	将3个div区块全部左浮,再给左边的设置margi="-100%",给右边的设置margin="-200px"
	再将中间的div区块挤出来margin-left:200px;margin-right:200px;
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>双飞翼</title>
	<style type="text/css">
	.boy{
		padding: 0;
		margin:0;/*将boy的内外边距为0*/
	}
	.top{
		width: 100%;
        height: 60px;
        background-color: #888;
	}

	.one{
		width: 1000px;
		min-height: 100%;
		background-color: #000;
		margin: auto;
	}
	.footer{
		width: 100%;
        height: 60px;
        background-color: #888;
        clear: both;/*清除浮动,否者会塌陷*/
	}
	.text{
		width: 1000px;
		height: 600px;
		background-color: #ff0;
		margin: auto;/*将div居中*/
	}
    .body{
		margin-right: 200px;/*将左右的两行挤出来,实现网页自适应*/
		margin-left:200px;
		text-align: center;/*文本居中*/

	}
	.left{
		width: 200px;
		height: 600px;
		background-color:#ff0;
		float: left;/*左浮动*/
		margin-left: -100%;/*将左边的div返回原来的位置*/
		text-align: center;/*文本居中*/
	}
	.reigth{
		width: 200px;
		height: 600px;
		background-color:#00fa9a;
		float: left;/*左浮*/
		margin-left: -200px;/*将右边的区块移到原来的位置就是-200px*/
		text-align: center;/*文本居中*/
	}
	.ke{
		width: 100%;/*设置宽为100%*/
		height: 600px;
		background-color:#0ff; 
        float: left;
    }
       
	</style>
</head>
<body>
	<div class="top">
	<div class="one"></div>
	</div>
	<div class="text">
	<div class="ke">
	<div class="body">中间</div><!--给body套上一个空壳,防止盒子撑大-->
	</div>
	<div class="left">左边</div>
	<div class="reigth">右边</div>
	</div>
	<div class="footer">
	<div class="one"></div>
	</div>
	思路:
	首先创建一个大盒子,包含着3个元素并设置高度,然后水平居中。
	再创建3个div盒子先设置中间的区块并设置100%的宽度,然后设置左右区块,
	将3个div区块全部左浮,再给左边的设置margi="-100%",给右边的设置margin="-200px"
	再将中间的div区块挤出来margin-left:200px;margin-right:200px;
</body>
</html>


这个是圣杯3列布局,用到了浮动.相对定位.margin的设置,大致跟双飞翼布局差不多
思路:<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style type="text/css">
        .boy{
		padding: 0;
		margin:0;/*将boy的内卫边距为0*/
	}
	.top{
		width: 100%;
        height: 60px;
        background-color: #888;
	}

	.one{
		width: 1000px;
		min-height: 100%;
		background-color: #000;
		margin: auto;
	}
	.footer{
		width: 100%;
        height: 60px;
        background-color: #888;
        clear: both;/*清除浮动,否者会塌陷*/
    }
    .text{
    	width: 600px;
    	margin :auto;/*清除浮动*/
    	background-color: #00ffff;
    	padding: 0 200px;/*内边距为上下为左右为200px*/
    	overflow: hidden;/*不显示滚动条*/
    }
    .text .body{
    	width: 100%;
    	height:600px;
    	background-color: #20b2aa;
    	
        float: left;/*3个div都要左浮*/
    }
    .text .left{
    	width: 200px;
    	height: 600px;
    	background-color: #696969;
    	float: left;
    	margin-left: -100%;/*div回到原来的位置*/
    	position: relative;/*相对定位*/
    	left: -200px;/*向左边移到200px*/
    	
    }
    .text .reigth{
    	width: 200px;
    	height: 600px;
    	background-color: #800080;
    	float: left;
    	margin-left: -200px;/*div回到原来的位置*/
    	position: relative;/*相对定位*/
    	right: -200px;/*向右边移到200px*/
    
    }
	</style>
</head>
<body>
		<div class="top">
	<div class="one"></div>
	</div>
	<div class="text">
	<div class="body">中间</div>
	<div class="left">左边</div>
	<div class="reigth">右边</div>
	</div>
	<div class="footer">
	<div class="one"></div>
	</div>
</body>
</html>
	
运行实例 »
点击 "运行实例" 按钮查看在线实例

双飞翼.jpg双飞翼2.jpg行实例 »

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


批改状态:合格

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学