.两栏自适应和三栏自适应

两栏自适应:左侧固定宽度 右侧自适应的状态 随着浏览器的窗口改变大小(左侧浮动,右侧触发BFC) ​ 三栏自适应: 左右侧固定宽度 中间自适应 随着浏览器的窗口改变大小(左侧左浮动,右侧右浮动,中间触发BFC)

原因:浮动 脱离标准流不脱离文本流 ,浮动的标签提升层级会覆盖正常标签

解决办法(特性6,4):bfc就是页面上的一个独立容器,容器里面的子标签不会影响外面标签

BFC 的区域不会与 float 的标签区域重叠

触发bfc的条件 触发bfc只有overflow属性能用

  • 两栏自适应

    <!DOCTYPE html>
    <html lang="en">
    ​
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <style>
            .wrap .left {
                width: 200px;
                height: 300px;
                background-color: red;
                float: left;
            }
    ​
            .wrap .right {
                height: 350px;
                background-color: aquamarine;
    ​
                /* 触发bfc */
                overflow: hidden;
                overflow: scroll;
                overflow: auto;
    ​
    ​
                /* 以下不能用 */
                /* float: left;
                float: right; */
    ​
                /* display: inline-block; */
    ​
                /* position: absolute;
                position: fixed; */
    ​
            }
    ​
          
        </style>
    </head>
    ​
    <body>
        <div class="wrap">
            <div class="left">left</div>
            <div class="right">出师表出师表出师出师表出师出师表出师出师表出师出师表出师出师表出师出师表出师出师表出师出师表出师表出师表出师表</div>
        </div>
    </body>
    ​
    </html>
  • 三栏自适应

    <!DOCTYPE html>
    <html lang="en">
    ​
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <style>
            .wrap .left {
                width: 200px;
                height: 200px;
                background-color: red;
                float: left;
    ​
            }
    ​
            .wrap .right {
                width: 200px;
                height: 200px;
                background-color: aquamarine;
                float: right;
            }
    ​
            .wrap .center {
    ​
                height: 300px;
                background-color: pink;
    ​
                /* 触发bfc */
                overflow: hidden;
                overflow: scroll;
                overflow: auto;
    ​
    ​
                /* 以下不能用 */
                /* float: left;
                float: right; */
    ​
                /* display: inline-block; */
    ​
                /* position: absolute;
                position: fixed; */
            }
    ​
            /* • 原因:浮动的标签会覆盖正常标签 • 
            解决办法(特性4):BFC的区域不会与float的标签区域重叠 */
        </style>
    </head>
    ​
    <body>
        <div class="wrap">
            <div class="left">left</div>
    ​
            <div class="right">right </div>
            <div class="center">center哈哈哈哈哈哈哈哈呵呵呵哈哈哈呵呵呵哈哈哈呵呵呵哈哈哈呵呵呵哈哈哈呵呵呵呵呵呵</div>
        </div>
    </body>
    ​
    </html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值