flex佈局

// 3. flex
.container{

    display:flex; //塊級元素使用flex , 行內元素使用 inline-flex 來指定本元素爲彈性盒子 ,Webkit 內核的瀏覽器,必須加上-webkit前綴。

    // 1、容器屬性:
    // 1. flex-direction       (排列方向)        row
    // 2. flex-wrap:           (換行方式)        nowrap
    // 3. flex-flow            (排列方向+換行)   row nowrap
    // 4. justify-content      (主軸對齊方式)    flex-start
    // 5. align-items          (交叉軸對齊方式)  stretch
    // 6. align-content        (多軸對齊方式)    stretch

    //////////////////////////////////////////////////////
    // 1.flex-direction 項目的排列方向 (row | row-reverse | column | column-reverse)
    // row(默認值):主軸爲水平方向,起點在左端。
    // row-reverse:主軸爲水平方向,起點在右端。
    // column:主軸爲垂直方向,起點在上沿。
    // column-reverse:主軸爲垂直方向,起點在下沿。
    flex-direction: row;

    // 2.flex-wrap 若是一條軸線排不下,如何換行 (nowrap | wrap | wrap-reverse)
    // nowrap(默認):不換行。
    // wrap:換行,第一行在上方。
    // wrap-reverse:換行,第一行在下方。

    // 3.flex-flow (flex-direction屬性和flex-wrap屬性的簡寫形式,默認值爲row nowrap。)
    //flex-flow: row nowrap;

    // 4.justify-content 項目在主軸上的對齊方式 (flex-start | flex-end | center | space-between | space-around;)
    // flex-start(默認值):左對齊
    // flex-end:右對齊
    // center: 居中
    // space-between:兩端對齊,項目之間的間隔都相等。
    // space-around:每一個項目兩側的間隔相等。因此,項目之間的間隔比項目與邊框的間隔大一倍。
    justify-content: space-between;

    // 5.align-items 項目在交叉軸上如何對齊。 (flex-start | flex-end | center | baseline | stretch;)
    // flex-start:交叉軸的起點對齊。
    // flex-end:交叉軸的終點對齊。
    // center:交叉軸的中點對齊。
    // baseline: 項目的第一行文字的基線對齊。
    // stretch(默認值):若是項目未設置高度或設爲auto,將佔滿整個容器的高度。
    align-items: center;

    // 6.align-content  (多行)多根軸線的對齊方式。若是項目只有一根軸線,該屬性不起做用。
    // (flex-start | flex-end | center | space-between | space-around | stretch;)
    // flex-start:與交叉軸的起點對齊。
    // flex-end:與交叉軸的終點對齊。
    // center:與交叉軸的中點對齊。
    // space-between:與交叉軸兩端對齊,軸線之間的間隔平均分佈。
    // space-around:每根軸線兩側的間隔都相等。因此,軸線之間的間隔比軸線與邊框的間隔大一倍。
    // stretch(默認值):軸線佔滿整個交叉軸。
    //align-content: stretch;
    //////////////////////////////////////////////////////

    div.item{
        // 2、容器屬性:
        // 1. order:         項目的排列順序。數值越小,排列越靠前,默認爲0。;
        // 2. flex-grow:     屬性定義項目的放大比例,默認爲0,即若是存在剩餘空間,也不放大。;
        // 3. flex-shrink:   屬性定義了項目的縮小比例,默認爲1,即若是空間不足,該項目將縮小。;
        // 4. flex-basis:    屬性定義了在分配多餘空間以前,項目佔據的主軸空間,它的默認值爲auto,即項目的原本大小;
        // 5. flex:          flex-grow, flex-shrink 和 flex-basis的簡寫,默認值爲0 1 auto。後兩個屬性可選;
        //                   該屬性有兩個快捷值:auto (1 1 auto) 和 none (0 0 auto)。
        //                   建議優先使用這個屬性,而不是單獨寫三個分離的屬性,由於瀏覽器會推算相關值。
        // 6. align-self:    align-self屬性容許單個項目有與其餘項目不同的對齊方式
        //                   (auto | flex-start | flex-end | center | baseline | stretch),
        //                   可覆蓋align-items屬性。默認值爲auto,表示繼承父元素的align-items屬性,
        //                   若是沒有父元素,則等同於stretch。;
    }

}
body{
    // margin:0;
}
.header{
    min-height:50px;
    background: #f4f4f4;
}
.box{
    display:flex;
    .item{
        flex:auto;
        min-height:300px;
        &:nth-child(1){
            min-width:150px;
            background: #eee;
        }
        &:nth-child(2){
            background:#666;
            display:flex;
            // justify-content:space-between;
            // justify-content: flex-start;
            // justify-content:space-between;
            flex-wrap: wrap;
            // justify-content:space-around;
            // align-items:stretch;
            // (flex-start | flex-end | center | space-between | space-around | stretch;)
            align-content: flex-start;
            .goodsItem{
                flex:none;
                width:100px;
                height:100px;
                background: #f3f3f3;
                border:1px solid #666;
                margin:2px;
            }
        }
        &:nth-child(3){
            min-width:50px;
            background:#eee;
        }
    }
}
相關文章
相關標籤/搜索