移动web flex 弹性布局要点一

127 阅读1分钟

flex 弹性布局要点一

变成弹性盒子模型特点: display: flex;

1.所有的子元素会在强制一行上显示

2.子元素默认宽度 由内容撑开

3.高度与父元素等高

4.与浮动不同,不会脱离标准流

主轴对齐方式 justify-content: flex-start 默认值

justify-content: center; jcc 居中 
justify-content: space-between; jc sb 两侧对齐居中 
justify-content: space-around; jct sad 间隙环绕每个盒子居中 
justify-content: space-evenly; jct say 间隙相同居中
justify-content: flex-end; jct fd 右对齐
justify-content: flex-start; 默认值左对齐

侧轴对齐方式 align-items:

align-items: center; aic 侧轴居中 
align-items: flex-end; ait fs 侧轴定到底部  

伸缩比 属性flex 方便更改同级弹性盒子的大小

文字过多需添加限制显示的行数

display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;  (限制的行数)
overflow: hidden;