css-圣杯布局和双飞翼布局

1.圣杯布局:

(1)父元素中包含左中右三个盒子,并且让他们分别左浮动。

(2)将中间的盒子宽度设为100%,并且它在html中代码位置放在左右代码位置的上面(就是所说的第一个渲染)。

(3)左右两边使用margin-left的负值,使他们与中间的盒子同行,(左边:-100%,右边:-右边盒子的宽度)。

(4)父元素用padding为左右盒子留位置。

(5)用相对定位将左右盒子移到正确的位置上

(6)给父元素清除浮动

代码如下:

<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>圣杯布局</title>
	<style type="text/css">
	.main{width: 810px;height: 400px;border: 1px  blue solid;padding-top: 25px;padding-left: 10px;padding-right: 10px;}
	._center{width: 100%;height: 350px;text-align: center;line-height: 350px;float: left;background-color: #eeeeee}
	._left{width: 200px;height: 350px;left: 20px;top:25px;text-align: center;line-height: 350px;float: left;margin-left: -100%;background-color: red;}
	._right{width: 200px;height: 350px;right:20px;top:25px;text-align: center;line-height: 350px;float: left;margin-left:-200px;background-color: green;}
	</style>
</head>
<body>
	<div class="main clearfix">
		<div  class="_center">我是中间</div>
		<div class="_left">我是左边</div>
		<div  class="_right">我是右边</div>
	</div>
</body>
</html>

效果图:

2.双飞翼布局:
(1)父元素中包含左中右三个盒子,并且让他们分别左浮动。

(2)将中间的盒子宽度设为100%,并且它在html中代码位置放在左右代码位置的上面(就是所说的第一个渲染)。

(3)左右两边使用margin-left的负值,使他们与中间的盒子同行,(左边:-100%,右边:-右边盒子的宽度)。

(4)给中间元素设置子元素,并给其左右margin为左右盒子留位置

(6)给父元素清除浮动.

代码如下:

<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>双飞翼布局</title>
	<style type="text/css">
	.main{width: 800px;height: 400px;padding-top: 25px;margin: 0;}
	._center{width: 100%;height: 350px;float: left;background-color: #eeeeee;}
	._center>div{margin: 0 200px 0 200px;}
	._left{width: 200px;height: 350px;left: 20px;top:25px;text-align: center;line-height: 350px;float: left;margin-left: -100%;background-color: red;}
	._right{width: 200px;height: 350px;right:20px;top:25px;text-align: center;line-height: 350px;float: left;margin-left:-200px;background-color: green;}
	</style>
</head>
<body>
	<div class="main clearfix">
		<div  class="_center">
			<div>我是中间我是中间我是中间我是中间我是中间我是中间我是中间我是中间我是中间我是中间我是中间我是中间我是中间我是中间我是中间我是中间我是中间我是中间我是中间我是中间我是中间我是中间我是中间</div>
		</div>
		<div class="_left">我是左边</div>
		<div  class="_right">我是右边</div>
	</div>
</body>
</html>

效果如下:

注:为中间元素设置子元素,并为其设置margin,目的是为了中间元素的内容可以在中间显示,margin的左右值为左右盒子的宽度。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值