“固比固”布局——“圣杯”布局

“固比固”布局也叫“圣杯”布局,它们实现的都是三栏布局,两边的盒子宽度固定,中间盒子自适应。本章用了5种方式来实现。
浮动布局,绝对定位,flex-box布局,table布局,grid布局

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            *{
                padding: 0;
                margin: 0;
            }
            .layout{
                margin-top: 20px;
            }
            .layout article div{
                min-height: 100px;
            }
        </style>
    </head>
    <body>
        <section class="layout float">
            <style media='screen'>
                .layout.float .left{
                    float: left;
                    width: 300px;
                    background-color: red;
                }
                .layout.float .right{
                    float: right;
                    width: 300px;
                    background-color: blue;
                }
                .layout.float .center{
                    background-color: yellow;
                }
            </style>
            <article class="left-center-right">
                <div class="left"></div>
                <div class="right"></div>
                <div class="center">
                    <h1>浮动解决方案</h1>
                    1.这是三栏布局
                    2.这是三栏布局中间部分
                </div>

            </article>
        </section>

        <section class="layout absolute">
            <style>
                .layout.absolute .left-center-right>div{
                    position: absolute;
                }
                .layout.absolute .left{
                    left: 0;
                    width: 300px;
                    background-color: red;
                }
                .layout.absolute .center{
                    left: 300px;
                    right: 300px;
                    background-color: yellow;
                }
                .layout.absolute .right{
                    right: 0;
                    width: 300px;
                    background-color: blue;
                }
            </style>
            <article class="left-center-right">
                <div class="left"></div>
                <div class="center">
                    <h1>绝对定位解决方案</h1>
                    1.这是三栏布局绝对定位中间部分
                    2.这是三栏布局绝对定位中间部分
                </div>
                <div class="right"></div>
            </article>
        </section>

        <section class="layout flexbox">
            <style>
                .layout.flexbox{
                    margin-top: 140px;
                }
                .layout.flexbox .left-center-right{
                    display: flex;
                }
                .layout.flexbox .left{
                    width: 300px;
                    background-color: red;
                }
                .layout.flexbox .center{
                    flex: 1;
                    background-color: yellow;
                }
                .layout.flexbox .right{
                    width: 300px;
                    background-color: blue;
                }
            </style>
            <article class="left-center-right">
                <div class="left"></div>
                <div class="center">
                    <h1>flecbox解决方案</h1>
                    1.这是三栏布局flecbox间部分
                    2.这是三栏布局flecbox中间部分
                </div>
                <div class="right"></div>
            </article>
        </section>

        <section class="layout table">
            <style>
                .layout.table .left-center-right{
                    width: 100%;
                    display: table;
                    height: 100px;
                }
                .layout.table .left-center-right>div{
                    display: table-cell;
                }
                .layout.table .left{
                    width: 300px;
                    background-color: red;
                }
                .layout.table .center{
                    background-color: yellow;
                }
                .layout.table .right{
                    width: 300px;
                    background-color: blue;
                }               
            </style>
            <article class="left-center-right">
                <div class="left"></div>
                <div class="center">
                    <h1>table解决方案</h1>
                    1.这是三栏布局table间部分
                    2.这是三栏布局table中间部分
                </div>
                <div class="right"></div>
            </article>
        </section>

        <section class="layout grid">
            <style>
                .layout.grid .left-center-right{
                    display: grid;
                    width: 100%;
                    grid-template-rows: 100px;
                    grid-template-columns: 300px auto 300px;
                }
                .layout.grid .left{
                    background-color: red;
                }
                .layout.grid .center{
                    background-color: yellow;
                }
                .layout.grid .right{
                    background-color: blue;
                }
            </style>
            <article class="left-center-right">
                <div class="left"></div>
                <div class="center">
                    <h1>grid解决方案</h1>
                    1.这是三栏布局grid间部分
                    2.这是三栏布局grid中间部分
                </div>
                <div class="right"></div>
            </article>
        </section>
    </body>
    
</html>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 由于5.1放假,今天学生们都补课了,今天儿子说想要爆兽猎人的蛋,我也不知道是什么东西,反正是玩具,到淘宝一...
    实验小学一九班艾自豪阅读 230评论 0 0
  • 西周时中国一个非常古老的朝代,是一个非常古老的朝代。 著名的史学家钱穆先生认为,建国需要三点,其中之一就是立国精神...
    张子孺阅读 498评论 0 1
  • 我是一只随波逐流的小船 你是一片静谧的港湾 你希望留住我疲倦的身影 我却不能承诺你一个准确的时间
    一叶茶阅读 384评论 4 3
  • 当我们点击删除按钮时想先弹出一个确认删除的弹框,就需要使用到confirm****效果图****
    WangYatao阅读 621评论 0 0