• 圣杯+双飞翼 自适应布局


    一、圣杯布局

    左右固定200px,中间自适应

    • 左右两个div左右浮动,中间div写到前面
    • 通过margin-left:-100%;来调整到同一行
    • 父容器添加左右padding,左右div相对定位

    详细代码如下:

    
    <!doctype html>
    <html>
        <head>
            <meta charset="utf-8"/>
            <title>圣杯布局</title>
            <style>        
    *{
        margin:0;
    }
    html{
        height:100%;
    }
    .box{
        800px;
        height:300px;
        border:1px solid black;
        margin:0 auto;
        background:#0ff;
        padding:0px 200px;
    }
    .left{
        200px;
        height:300px;
        background:#f00;
        float:left;
        margin-left:-100%;
        position:relative;
        left:-200px;
    }
    .center{
        100%;
        height:300px;
        background:#0f0;
        float:left;    
    }
    .right{
        200px;
        height:300px;
        background:blue;
        float:right;    
        margin-left:-100%;
        position:relative;
        right:-200px;    
    }
            </style>
        </head>
        <body>
            <div class="box">
                <div class="center"></div>
                <div class="left"></div>            
                <div class="right"></div>
            </div>
        </body>
    </html>
    

    运行结果如下图:

    二、双飞翼布局

    左右固定200px,中间自适应

    • 左右两个div左右浮动,中间div写到前面
    • 通过margin-left:-100%;来调整到同一行
    • 中间div添加一个子节点div,设置margin调整位置

    具体代码如下:

    
    <!doctype html>
    <html>
        <head>
            <meta charset="utf-8"/>
            <title>双飞翼布局</title>
            <style>
            *{
        margin:0;
    }
    html{
        height:100%;
    }
    .box{
        1000px;
        height:300px;
        border:1px solid black;
        margin:0 auto;
        background:#0ff;    
    }
    .left{
        200px;
        height:300px;
        background:#f00;
        float:left;
        margin-left:-100%;    
    }
    .center{
        100%;
        height:300px;
        background:#0f0;
        float:left;    
    }
    .right{
        200px;
        height:300px;
        background:blue;
        float:right;    
        margin-left:-100%;    
    }
    .conter{
        margin:0 200px;
    }
            </style>
        </head>
        <body>
            <div class="box">
                <div class="center">
                    <div class="conter">
                        双飞翼布局
                    </div>
                </div>
                <div class="left"></div>            
                <div class="right"></div>
            </div>    
        </body>
    </html>
    

    运行结果如下图:

    加关注 持续更新

    原文地址:https://segmentfault.com/a/1190000015634014

  • 相关阅读:
    【翻译】在Sencha应用程序中使用插件和混入
    Codeforces Round #306 (Div. 2) A
    自己定义控件-仿iphone之ToggleButton&VoiceSeekBar
    .m文件导入C++头文件带来的错误
    Permutations
    ceph命令拷屏
    Azure 3 月新公布
    Azure 本月最新活动,速度Mark!
    直接刷脸?一元就能搞定会议签到!
    Azure SQL的DTU和eDTU到底是个什么鬼
  • 原文地址:https://www.cnblogs.com/lalalagq/p/9979914.html
Copyright © 2020-2023  润新知