display:flex
flex-direction属性决定主轴的方向(即项目的排列方向)。
flex-direction: row | row-reverse | column | column-reverse;
flex-wrap属性定义,如果一条轴线排不下,如何换行。
flex-wrap: nowrap | wrap | wrap-reverse;
nowrap(默认):不换行。
wrap:换行,第一行在上方。
wrap-reverse:换行,第一行在下方。
flex-flow属性是flex-direction属性和flex-wrap属性的简写形式,默认值为row nowrap。
flex-flow:
justify-content: flex-start | flex-end | center | space-between | space-around;
align-items属性定义项目在交叉轴上如何对齐。
align-items: flex-start | flex-end | center | baseline | stretch;
align-content属性定义了多根轴线的对齐方式。如果项目只有一根轴线,该属性不起作用。
align-content: flex-start | flex-end | center | space-between | space-around | stretch
以下6个属性设置在项目上。
如果所有项目的flex-grow属性都为1,则它们将等分剩余空间(如果有的话)。如果一个项目的flex-grow属性为2,其他项目都为1,则前者占据的剩余空间将比其他项多一倍。
如果所有项目的flex-shrink属性都为1,当空间不足时,都将等比例缩小。如果一个项目的flex-shrink属性为0,其他项目都为1,则空间不足时,前者不缩小。
负值对该属性无效。
该属性有两个快捷值:auto (1 1 auto) 和 none (0 0 auto)。
建议优先使用这个属性,而不是单独写三个分离的属性,因为浏览器会推算相关值。
align-self: auto | flex-start | flex-end | center | baseline | stretch;
align-self属性允许单个项目有与其他项目不一样的对齐方式,可覆盖align-items属性。默认值为auto,表示继承父元素的align-items属性,如果没有父元素,则等同于stretch。
ps:
flex 最后一行左对齐
.box:after { content: ""; flex: auto; }
上面的布局的代码为
.outbox{width:100%;height: 100%;display:flex;flex-direction:column;}
.top{height: 80px;background: red;}
.bottom{height: 50px;background: green;}
.main{flex:1;}
.main_con{height: 100%;background:#fff; display:flex}
.left{ width:200px; float:left; height:100%; background:#369;}
.right{ float:left;height:100%;flex:1;}
在浏览器中横行排列
.page-contain{display: flex; align-items: center; flex-grow: 1;height: 100%;}
.contain{display: flex;flex-direction: row; height: 32rem; box-shadow: 10px 50px 100px rgba(0, 0, 0, .3);}
.banner1{ background:red; width: 37.5rem}
.banner2{ background:gray; width: 27.5rem ; order: 2;}
.banner3{ background:blue; width: 42.5rem}
.banner4{ background:black; width: 27.5rem}
.banner5{ background:#ff1122;width: 30.5rem}
.banner6{ background:#ccc000;width: 43.5rem}
.banner7{ background:#00ffaa;width: 32.5rem}
.panel{ height: 32rem; line-height: 32rem; font-size: 10rem; text-align: center; color: beige}
骰子的排列
.saizi{display: flex;height: 100%;}
.page{ background: black; justify-content: space-around;}
.public{ width: 100px; height: 100px; background: #ddd; border-radius: 10px; box-sizing: border-box;
box-shadow: 2px 2px 2px rgba(0, 0, 0, .2); border: 5px solid #fff; align-items: center;}
.saizi span{ width: 20px; height: 20px; border-radius: 20px; display: inline-block;background: black;}
.one{justify-content: center; align-items: center; }
.two{ justify-content: space-between;}
.two .specia_one{align-self:flex-end;}
.three{ justify-content: space-between;}
.three .specia_one{align-self:center;}
.three .specia_two{align-self:flex-end;}
.four{ justify-content: space-between;}
.four .specia_one,.four .specia_two{align-self: flex-end;}
.spe{ justify-content: space-between;}
.four{ flex-direction: column;justify-content:space-between;}
.five{ flex-direction: column;justify-content:space-between;}
.six{flex-direction: column;justify-content:space-between;}
.spe_sevec{flex-direction: column; justify-content: space-between;}
.seven{justify-content:space-around; height: 40px; width: 100%;}
.seven .one{align-self: center;}
.seven .two{align-self: flex-end}
.seven_spea{ justify-content: space-around; height: 20px;width: 100%;}
.eight_spea{flex-direction: column;}
.eight{justify-content: space-around; width: 100%;}
.night_spea{flex-direction: column;}
.night{justify-content: space-around; width: 100%;}
flex布局 一行排两列或者三列
.list_cai{ display: flex; justify-content: space-around; flex-direction: row; flex-wrap: wrap;} 父节点
.list_cai .list_cai_li{ width: 45%; height:100px; border: 1px solid orange; border-radius: 20rpx;} 子节点
flex布局最后的一个或者两个元素 靠左对齐
.list_cai:after {content: "";flex: auto; }