Flex

作者: zz77zz | 来源:发表于2017-08-20 13:36 被阅读24次

    Flex布局

    这是国外大神专门讲flex布局讲的超级细,虽然没有看完
    边玩游戏边学习flex

    • 块级布局侧重垂直方向、行内布局侧重水平方向,flex布局是跟方向无关的
    • flex布局可以实现空间自动分配、自动对齐(flexible:弹性布局);
    • flex适用于简单的线性布局,更复杂的布局要交给Grid,这篇文章写的挺好,学到不少。
    常用flex属性
    • flex container(容器)属性?
      flex-direaction:方向
      flex-wrap:换行
      flex-flow:上面另个的简写
      justify-content:主轴方向对齐方式
      align-items:侧轴对齐方式
      align-content:多行/列内容对齐方式(用的少)
    • flex item属性?
      flex-grow:增长比例(空间过多时)
      flex-shrink:收缩比例(空间不够时)
      flex-basis:默认大小(一般不用)
      order:顺序(代替双飞翼)
      align-self:自身对齐方式
      align-content:多行/列内容对齐方式(用的少)

    结合学习内容写个骰子布局

        <html>
        <head>
        <meta charset="utf-8">
        <title></title>
        <style media="screen">
        .first-face {
        display: flex;
        justify-content: center;
        align-items: center;
        }
    
        .second-face {
        display: flex;
        justify-content: space-between;
        }
    
        .second-face .pip:nth-of-type(2) {
        align-self: flex-end;
        }
    
        .third-face {
        display: flex;
        justify-content: space-between;
        }
    
        .third-face .pip:nth-of-type(2) {
        align-self: center;
        }
    
        .third-face .pip:nth-of-type(3) {
        align-self: flex-end;
        }
    
        .fourth-face, .sixth-face {
        display: flex;
        justify-content: space-between;
        }
    
        .fourth-face .column, .sixth-face .column {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        }
    
        .fifth-face {
        display: flex;
        justify-content: space-between;
        }
    
        .fifth-face .column {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        }
    
        .fifth-face .column:nth-of-type(2) {
        justify-content: center;
        }
    
        /* OTHER STYLES */
    
        * {
        box-sizing: border-box;
        }
    
        html, body {
        height: 100%;
        }
    
        body {
        display: flex;
        align-items: center;
        justify-content: center;
        vertical-align: center;
        flex-wrap: wrap;
        align-content: center;
        font-family: 'Open Sans', sans-serif;
        background: linear-gradient(top, #222, #333);
        }
    
        [class$="face"] {
        margin: 16px;
        padding: 4px;
    
        background-color: #e7e7e7;
        width: 104px;
        height: 104px;
        object-fit: contain;
    
        box-shadow:
            inset 0 5px white,
            inset 0 -5px #bbb,
            inset 5px 0 #d7d7d7,
            inset -5px 0 #d7d7d7;
            border-radius: 10%;
        }
    
        .pip {
        display: block;
        width: 24px;
        height: 24px;
        border-radius: 50%;
        margin: 4px;
        background-color: #333;
        box-shadow: inset 0 3px #111, inset 0 -3px #555;
        }
        </style>
        </head>
        <body>
        <div class="first-face">
          <span class="pip"></span>
        </div>
        <div class="second-face">
          <span class="pip"></span>
          <span class="pip"></span>
        </div>
        <div class="third-face">
          <span class="pip"></span>
          <span class="pip"></span>
          <span class="pip"></span>
        </div>
        <div class="fourth-face">
          <div class="column">
            <span class="pip"></span>
            <span class="pip"></span>
          </div>
          <div class="column">
            <span class="pip"></span>
            <span class="pip"></span>
          </div>
        </div>
        <div class="fifth-face">
          <div class="column">
            <span class="pip"></span>
            <span class="pip"></span>
          </div>
          <div class="column">
            <span class="pip"></span>
          </div>
          <div class="column">
            <span class="pip"></span>
            <span class="pip"></span>
          </div>
        </div>
        <div class="sixth-face">
          <div class="column">
            <span class="pip"></span>
            <span class="pip"></span>
            <span class="pip"></span>
          </div>
          <div class="column">
            <span class="pip"></span>
            <span class="pip"></span>
            <span class="pip"></span>
          </div>
        </div>
        </body>
        </html>`
    
    效果图效果图

    相关文章

      网友评论

        本文标题:Flex

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