美文网首页
三栏布局(垂直方向)的四种方案

三栏布局(垂直方向)的四种方案

作者: 陈裔松的技术博客 | 来源:发表于2018-11-26 17:05 被阅读0次

总结完水平方向的三栏布局之后,再来总结下垂直方向的三栏布局,这在移动端的开发中非常常见。

要求:假设宽度已知,其中上栏,下栏高度各为100px,中间高度自适应。

总结:在正常情况下,以下四种方案都能达到要要求。但是当中间栏的内容较多时,方案3的表格布局解决方案会占据上栏和下栏的空间,所以不建议采用。

方案1:绝对定位解决方案

  • html部分
    <section class="layout">
        <div class="top"></div>
        <div class="center">
            <h1>绝对定位解决方案</h1>
            <p>这是三栏布局中间部分</p>
            <p>这是三栏布局中间部分</p>
        </div>
        <div class="bottom"></div>
    </section>
  • css部分
        .layout div{
            min-height: 100px;
            width: 100%;
            position: absolute;
        }
        .layout{
            height: 100vh;
            position: relative;
        }
        .top{
            top: 0;
            background-color: red;
        }
        .bottom{
            bottom: 0;
            background-color: blue;
        }
        .center{
            top: 100px;
            bottom: 100px;
            overflow: auto;
            background-color: yellow;
        }

方案2:flexbox解决方案

  • html部分
    <section class="layout">
        <div class="top"></div>
        <div class="center">
            <h1>flexbox解决方案</h1>
            <p>这是三栏布局中间部分</p>
            <p>这是三栏布局中间部分</p>
        </div>
        <div class="bottom"></div>
    </section>
  • css部分
        .layout div{
            min-height: 100px;
        }
        .layout{
            height: 100vh;
            display: flex;
            flex-direction: column;
        }
        .top{
            background-color: red;
        }
        .bottom{
            background-color: blue;
        }
        .center{
            flex: 1;
            background-color: yellow;
            overflow: auto;
        }

方案3:表格布局解决方案

  • html部分
    <section class="layout">
        <div class="top row">
            <div class="top-cell cell"></div>
        </div>
        <div class="center row">
            <div class="center-cell cell">
                <h1>表格解决方案</h1>
                <p>这是三栏布局中间部分</p>
                <p>这是三栏布局中间部分</p>
            </div>
        </div>
        <div class="bottom row">
            <div class="bottom-cell cell"></div>
        </div>
    </section>
  • css部分
        .layout .row{
            display: table-row;
            min-height: 100px;
        }
        .layout .cell{
            display: table-cell;
        }
        .layout{
            height: 100vh;
            width: 100%;
            display: table;
        }
        .top{
            background-color: red;
        }
        .bottom{
            background-color: blue;
        }
        .center{
            overflow: auto;
            background-color: yellow;
        }

方案4:网格布局解决方案

  • html部分
    <section class="layout">
        <div class="top"></div>
        <div class="center">
            <h1>网格解决方案</h1>
            <p>这是三栏布局中间部分</p>
            <p>这是三栏布局中间部分</p>
        </div>
        <div class="bottom"></div>
    </section>
  • css部分
        .layout{
            height: 100vh;
            display: grid;
            grid-template-rows: 100px auto 100px;
            grid-template-columns: 100%;
        }
        .top{
            background-color: red;
        }
        .bottom{
            background-color: blue;
        }
        .center{
            overflow: auto;
            background-color: yellow;
        }

相关文章

  • 三栏布局(垂直方向)的四种方案

    总结完水平方向的三栏布局之后,再来总结下垂直方向的三栏布局,这在移动端的开发中非常常见。 要求:假设宽度已知,其中...

  • android布局

    线性布局* 布局方向,水平|垂直 android:orientation="vertical(垂直)|horizo...

  • 移动端-适配问题

    适配方案 固定高度,宽度自适应垂直方向使用固定的值,水平方向使用弹性布局,元素采用定值、百分比、flex布局等。这...

  • 页面架构

    布局解决方案 水平居中布局 垂直居中布局 水平垂直都居中的布局 多列布局 多列等分布局 多列等高布局 在多列布局的...

  • flex布局

    Flex布局特点 块级布局侧重垂直方向、行内布局侧重水平方向,flex布局是与方向无关的。 flex布局可以实现空...

  • flex 布局

    flex 布局特点 块级布局侧重垂直方向、行内布局侧重水平方向,flex布局与方向无关 flex布局可以实现空间自...

  • Flex布局

    Flex布局 一种新的布局方式-Flex布局块级布局侧重垂直方向,行内布局侧重水平方向,flex布局是与方向无关的...

  • Flutter 之线性布局 Row、Column、Flex

    简介 Row 水平布局 类似于水平方向的LinearLayout Column垂直布局 类似于垂直...

  • Flutter学习总结之四 常见Widget及页面跳转

    一.常见布局方式 Row,是水平方向的线性布局(linearlayout) Column,是垂直方向的线性布局(l...

  • CSS:垂直+水平居中/单位in

    水平+垂直居中:display: flex 布局下, margin auto 的生效不仅是水平方向,垂直方向生效。...

网友评论

      本文标题:三栏布局(垂直方向)的四种方案

      本文链接:https://www.haomeiwen.com/subject/xegbqqtx.html