flex布局常用樣式


 
// flex容器默認存在兩根軸:水平的主軸(main axis)和垂直的交叉軸(cross axis)
// flex 左對齊 頂對齊
.flex{
   displayflex;   //
   align-itemsflex-start;   // 項目在交叉軸上如何對齊
   justify-contentflex-start;   // 項目在主軸上的對齊方式
}
// flex 左右居中,上下居中
.flexCenter {
   displayflex;   //
   align-itemscenter ;   // 項目在交叉軸上如何對齊
   justify-contentcenter;   // 項目在主軸上的對齊方式
}
.flex-column{
   displayflex;
   flex-directioncolumn// 項目主軸的排列方向。column:主軸為垂直方向,起點在上沿。
   align-itemsflex-start;
   justify-contentflex-start;
}

// 垂直居中布局
.flexClsDirectcolumn {
   displayflex;
   flex-directioncolumn;
   flex-wrap: wrap;
   align-items: flex-start;
   justify-contentcenter;
}

.flexClsDirectcolumn >  div{
   white-spacenowrap;
}

// 左對齊布局
.flexClsDirectLeft {
   displayflex;
   flex-directionrow;
   flex-wrap: nowrap;
   justify-contentflex-start;
}
// 左對齊布局,換行
.flexClsDirectwWrapLeft {
   displayflex;
   flex-directionrow;
   flex-wrap: wrap;
   justify-contentflex-start;
}
// 居中布局,不換行自動撐開
.flexClsLeftLinkAutoWid {
   displayflex;
   flex-directionrow;
   flex-wrapnowrap;
   justify-contentspace-around;
   align-contentflex-start
}
// 左對齊布局,換行不撐開,直接緊跟上一個換行
.flexClsDirectwWrapLeftStart {
   displayflex;
   flex-directionrow;
   flex-wrap: wrap;
   justify-contentflex-start;
   align-contentflex-start
}
// 右對齊布局
.flexClsDirectRight {
   displayflex;
   flex-directionrow;
   flex-wrap: nowrap;
   justify-contentflex-end;
}
// 兩端對齊,不換行,項目之間的間隔都相等
.flexClsNowrapSpcBtw {
   displayflex;
   flex-directionrow;
   flex-wrap: nowrap;
   justify-contentspace-between;
}
// 兩端對齊,不換行,每個項目兩側的間隔相等
.flexClsNowrapSpcArd {
   displayflex;
   flex-directionrow;
   flex-wrap: nowrap;
   justify-contentspace-around;
}
// 兩端對齊,超出換行,每個項目兩側的間隔相等
.flexClsWrapSpcArd {
   displayflex;
   flex-directionrow;
   flex-wrap: wrap;
   justify-contentspace-between;
}
.flex1{
   flex1;
}

// 用於垂直布局,固定一個div高度,另一個div填充剩余的高度
.flexColumBox { 
   displayflex;
   flex-flowcolumn;
   align-itemsstretch;
}
// 固定高度
.fixedHig{
   flex0;
}
// 自動填充剩余區域
.autoFullHig{
   flex1;
}

// 用於水平布局,固定一個div的寬度,另一個div填充剩余的寬度 //父級flex
.flexWidthBox{
   displayflex;
}
// flex屬性是flex-grow(放大比例), flex-shrink(縮小比例) 和 flex-basis(根據剩余空間進行分配計算)的簡寫,默認值為0 1 auto。后兩個屬性可選。
// 自適應寬度的,css
.autoFullWidth{
   flex: 1  1  auto;
}
// 固定寬度,不放縮
.fixWidth{
   flex: 0  0  auto;
}






免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM