1.1. Flex 布局

采用 Flex 布局的元素,称为 Flex 容器(flex container),简称"容器"。它的所有子元素自动成为容器成员,称为 Flex 项目(flex item),简称"项目"。

1.1.1. 容器 属性列表

  • flex-direction #主轴的方向
  • flex-wrap #一条轴线排不下,如何换行
  • flex-flow # [flex-direction flex-wrap] 简单写法
  • justify-content #属性定义了项目在主轴上的对齐方式
  • align-items #定义项目在交叉轴上如何对齐
  • align-content #属性定义了多根轴线的对齐方式。如果项目只有一根轴线,该属性不起作用

1.1.2. 容器内 项目 属性列表

  • order #排序
  • flex-grow #放大
  • flex-shrink #缩小
  • flex-basis #项目的本来大小 一般用auto
  • flex [ flex-grow flex-shrink flex-basis ] #简写
  • align-self #单个项目有与其他项目不一样的对齐方式 可覆盖align-items属性

1.2. align-items (项目单行对齐)

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

1.3. align-content (项目多行对齐)

  • !!! 也就是多个交叉轴

1.4. flex-flow: row nowrap;

  • flex-direction 属性决定主轴的方向

    • row(默认值):主轴为水平方向,起点在左端。
    • row-reverse:主轴为水平方向,起点在右端。
    • column:主轴为垂直方向,起点在上沿。
    • column-reverse:主轴为垂直方向,起点在下沿。
  • flex-wrap 属性定义,如果一条轴线排不下,如何换行

    • nowrap(默认):不换行。
    • wrap:换行,第一行在上方。
    • wrap-reverse:换行,第一行在下方。

      1.5. justify-content

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

      1.6. css

      body {
              background-color: white;
          }
      
          * {
              margin: 0;
              padding: 0;
          }
      
          .container {
      
          }
      
          .header {
              position: -webkit-sticky;
              position: sticky;
              top: 0rem;
              width: 100%;
              height: 3.5rem;
              background-color: antiquewhite;
          }
      
          .content {
              width: auto;
              height: 50rem;
              display: -webkit-flex;
              display: flex;
              flex-flow: row nowrap;
              justify-content:flex-start;
          }
      
          .left_menu {
              width: 6.25rem;
              flex: 0 0 auto;
              background-color: greenyellow;
          }
          .right_contents {
              flex: 1 1 auto;
              background-color: skyblue;
          }
      
          .footer {
              position: -webkit-sticky;
              position: sticky;
              height: 1.25rem;
              bottom: 0px;
              background-color: antiquewhite;
          }
      

1.7. html

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>test</title>
    </head>
    <style type="text/css">
        ...
    </style>
    <body>
        <div class="container">
            <div class="header">
                头部
            </div>
            <div class="content">
                <div class="left_menu">
                    中-左侧
                    文本测试文本测试文本测试文本测试文本测试文本测试文本测试文本测试
                </div>
                <div class="right_contents">
                    中-右侧
                    文本测试文本文本测试文本测试文本测试文本测测试文本测试文本测测试文本测试文本测测试文本测试文本测测试文本测试文本测测试文本测试文本测试
                </div>
            </div>
            <div class="footer">
                底部
            </div>
        </div>
    </body>
</html>

results matching ""

    No results matching ""