三种方式实现:三栏布局(圣杯布局,双飞翼布局前端面试的布局问题)

1.float+margin

效果如下:


html代码如下:

 <div class="main">im center</div>
 <div class="left">im left</div>
 <div class="right"> im right</div>

css代码如下:

 *{
        padding: 0px;
        margin:0px;
    }
    .left{
        width:200px;
        height: 400px;
        background-color: bisque;
        float:left;
        margin-left: -100%;
        text-align: center;
    }
    .right{
        width:200px;
        height: 400px;
        background-color: bisque;
        float:left;
        margin-left: -200px;
        text-align: center;
    }
    .main{
        width: 100%;
        height: 400px;
        float: left;
        box-sizing: border-box;
        padding: 0 200px;//文字不被覆盖
        background-color: cadetblue;
        text-align: center;
    }

2.flex(woo~so easy right?)

html代码:

 <div class="content">
    <div class="left">im left</div>
    <div class="main">im center</div>
    <div class="right"> im right</div>
  </div>

css代码:

 *{
        padding: 0px;
        margin:0px;
    }
    .content{
        width: 100%;
        height:300px;
        display: flex;
    }
   .left{
        background-color: bisque;
        width: 200px;
   }
   .right{
       background-color:bisque;
       width: 200px;
   }
   .main{
       flex: 1;
       background-color: cadetblue;
   }

3.position:absolute+z-index

html代码:

 <div class="content">
    <div class="left">im left</div>
    <div class="main">im center</div>
    <div class="right"> im right</div>
 </div>

css代码:

 *{
        padding: 0px;
        margin:0px;
    }
    .content{
        width: 100%;
        height:300px;
    }
    .left{
        width: 200px;
        height: inherit;
        position: absolute;
        z-index: 1;
        background: bisque;
    }
    .main{
        width: 100%;
        height: inherit;
        background: cadetblue;
        position: relative;
        box-sizing: border-box;
        padding: 0 200px;
    }
    .right{
        width: 200px;
        height: inherit;
        background: bisque;
        position: absolute;
        top:0;
        right:0;
        z-index: 1;
    }


综合而言主要是这三种形式,当然也有更多的方法,主要是在div的排列顺序和position与float的变化。

好啦,赶快动手去试试吧~~

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值