三栏布局——圣杯+双飞翼

三栏布局

  • 圣杯布局的思路:
  1. 页面布局时,中间弹性区域放在最上层,首先渲染
  2. 给他们分别设置浮动:左栏,中间栏左浮动,右栏右浮动
  3. 使用负margin把左右两栏拉回同一行
  4. 接下来解决中间区域被遮挡
  5. 父元素设置padding给左右两栏留出空位
  6. 左右两栏再使用相对定位铺满
<style>
	/* 圣杯布局 */
	.box1 {
	  border: 1px solid red;
	  height: 100px;
	  padding: 0 80px;
	}
	.box1 .left {
	  width: 80px;
	  height: 100px;
	  background-color: rgb(185, 201, 253);
	  float: left;
	  margin-left: -100%;
	  position: relative;
	  left: -80px;
	}
	.box1 .right {
	  width: 80px;
	  height: 100px;
	  background-color: rgb(178, 224, 250);
	  float: left;
	  margin-left: -80px;
	  position: relative;
	  right: -80px;
	}
	.box1 .center {
	  width: 100%;
	  height: 100px;
	  background-color: rgb(141, 192, 250);
	  float: left;
	}
</style>
<body>
	<div class="box1">
	    <div class="center">圣杯布局中间弹性区域</div>
	    <div class="left">左固定</div>
	    <div class="right">右固定</div>
	</div>
</body>
  • 双飞翼布局的思路:
  1. 页面布局时,,中间弹性区域放在最上层,首先渲染
  2. 给他们分别设置浮动:左栏,中间栏左浮动,右栏右浮动
  3. 使用负margin把左右两栏拉回同一行
  4. 接下来解决中间区域被遮挡
  5. 给中间区域套一层div,设置宽度100%,浮动
  6. 里面内容区域设置左右margin来给两边区域让位
<style>
/* 双飞翼布局 */
.box2 {
  border: 1px solid red;
  height: 100px;
}
.box2 .center-box {
  width: 100%;
  float: left;
}
.box2 .center {
  height: 100px;
  background-color:rgb(141, 192, 250);
  margin: 0 80px;
}
.box2 .left {
  width: 80px;
  height: 100px;
  background-color: rgb(185, 201, 253);
  float: left;
  margin-left: -100%;
}
.box2 .right {
  width: 80px;
  height: 100px;
  background-color: rgb(178, 224, 250);
  float: left;
  margin-left: -80px;
}
</style>

<body>
<div class="box2">
  <div class="center-box">
    <div class="center">双飞翼布局中间弹性区域</div>
  </div>
  <div class="left">左固定</div>
  <div class="right">右固定</div>
</div>
</body>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Komorebi゛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值