zoukankan      html  css  js  c++  java
  • 浅谈flex布局

    Flex布局,俗称弹性布局,有了这个布局,咱们做的事情很多,以前那些很难实现比如说垂直居中之类都不存在了。

    盒模型布局依赖于float,display,定位之类的方式来布局,这种的布局对一些特殊布局来说很不方便,就如上面的垂直居中就不太好实现。

    现在就让我来介绍一个Flex布局方式

    他中的一些属性:

    • flex-direction
    • flex-wrap
    • flex-flow
    • justify-content
    • align-items
    • align-content

    在这里,声明一点,使用了display:flex;布局,其子元素内的floatclearvertical-align属性将失效

    flex-direction属性

    .box {
      flex-direction: row | row-reverse | column | column-reverse;
    }
    • row(默认值):主轴为水平方向,起点在左端。
    • row-reverse:主轴为水平方向,起点在右端。
    • column:主轴为垂直方向,起点在上沿。
    • column-reverse:主轴为垂直方向,起点在下沿。

    flex-wrap属性

    .box{
      flex-wrap: nowrap | wrap | wrap-reverse;
    }

    (1)nowrap(默认):不换行。

    (2)wrap:换行,第一行在上方。

    (3)wrap-reverse:换行,第一行在下方。

    flex-flow属性

    .box {
      flex-flow: <flex-direction> || <flex-wrap>;
    }

    flex-flow属性是flex-direction属性和flex-wrap属性的简写形式,默认值为row nowrap

     justify-content属性


    .box { justify-content: flex-start | flex-end | center | space-between | space-around; }
    • flex-start(默认值):左对齐
    • flex-end:右对齐
    • center: 居中
    • space-between:两端对齐,项目之间的间隔都相等。
    • space-around:每个项目两侧的间隔相等。所以,项目之间的间隔比项目与边框的间隔大一倍。

    align-items属性

    align-items属性定义项目在交叉轴上如何对齐

    .box {
      align-items: flex-start | flex-end | center | baseline | stretch;
    }
    • flex-start:交叉轴的起点对齐。
    • flex-end:交叉轴的终点对齐。
    • center:交叉轴的中点对齐。
    • baseline: 项目的第一行文字的基线对齐。
    • stretch(默认值):如果项目未设置高度或设为auto,将占满整个容器的高度。

    align-content属性

    .box {
      align-content: flex-start | flex-end | center | space-between | space-around | stretch;
    }

    • flex-start:与交叉轴的起点对齐。
    • flex-end:与交叉轴的终点对齐。
    • center:与交叉轴的中点对齐。
    • space-between:与交叉轴两端对齐,轴线之间的间隔平均分布。
    • space-around:每根轴线两侧的间隔都相等。所以,轴线之间的间隔比轴线与边框的间隔大一倍。
    • stretch(默认值):轴线占满整个交叉轴。
















  • 相关阅读:
    项目工作总结 (转)
    mysql-笔记 操作语句
    QTP自动化测试-excel sheet页数量过多--但是不能在qtp里被识别
    mysql-笔记 定义语句
    HDU
    CodeForces
    CodeForces
    CodeForces
    CodeForces
    CodeForces
  • 原文地址:https://www.cnblogs.com/kester/p/6798681.html
Copyright © 2011-2022 走看看