CSS经典布局 -- 圣杯布局 & 双飞翼布局

引言

圣杯布局和双飞翼布局都是比较经典的三栏布局,两种布局的页面效果基本相同。两种布局都是两侧宽度固定, 中间宽度自适应 且 中间内容优先渲染 的三栏布局

在这里插入图片描述

圣杯布局

圣杯布局DOM结构

 	<header>this is the header</header>
    <main>
      <div class="center">this is the center</div>
      <div class="left">this is the left</div>
      <div class="right">this is the right</div>
    </main>
    <footer>this is the footer</footer>

内容区域main包含三个div标签,class分别为center、left、right。(顺序很重要,center一定要放到最前面,确保其优先渲染)

圣杯布局样式

第一步,将内容区域设置padding,为左右两栏留出空间。并设置内容区域的各栏宽度,中间栏宽度 100%,让其自适应,两边栏宽度固定。(宽 / 高根据实际情况设置,这是数值是为了演示方便)

		main{
   
            padding-left: 200px; 
            padding-right: 150px;
        }
        .center {
   
            width: 100%;
            height: 200px;
        }
        .left {
   
            width: 200px; 
            height: 200px;
        }
        .right {
   
            width: 150px; 
            height: 200px;
        }

页面效果:

在这里插入图片描述
第二步,为三栏分别添加 float: left; (为了演示效果,添加了背景颜色)

修改后的CSS代码如下:

 		.center {
   
 			float: left;
            width: 100%;
            height: 200px;
            background-color: orange;
        }
        .left {
   
        	float: left;
            width: 200px; 
            height: 200px;
            background-color: red;
        }
        .right {
   
        	
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

爱划水de鲸鱼哥~

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

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

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

打赏作者

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

抵扣说明:

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

余额充值