当前位置:网站首页>flex布局属性简约速记
flex布局属性简约速记
2022-08-08 05:35:00 【Cirrod】
flex 布局
flex 布局原理
全称 flexible box,弹性布局。
如何开启:为元素添加 display: flex。
开启 flex 布局的元素,称为 flex 容器(flex container),其子元素成为容器成员,称为 flex 项目。
flex 布局原理:通过给父盒子添加 display: flex,来控制子盒子的位置和排列方式。
flex 布局父盒子常见属性
flex-direction
设置主轴方向
| 属性值 | 含义 |
|---|---|
| row | 默认值,从左到右 |
| row-reverse | 从右到左 |
| column | 从上到下 |
| column-reverse | 从下到上 |
justify-content
设置主轴子元素排列方式
| 属性值 | 含义 |
|---|---|
| flex-start | 默认值,从头开始 |
| flex-end | 从尾部开始 |
| center | 居中 |
| space-around | 平分剩余空间 |
| space-between | 两侧子元素贴边,再平分剩余空间 |
| space-evenly | 子盒间的间隙相等 |
flex-wrap
设置子元素是否换行
默认不换行,若子盒子宽度和大于父盒子,则会收缩!
| 属性值 | 含义 |
|---|---|
| wrap | 换行 |
| nowrap | 默认值,不换行 |
align-items
设置子元素在侧轴上的排列方式(子元素单行)
| 属性值 | 含义 |
|---|---|
| flex-start | 侧轴头部开始 |
| flex-end | 侧轴尾部开始 |
| center | 侧轴居中 |
| stretch | 默认值,拉伸(拉满整个侧轴),若子元素设置了高度则失效 |
align-content
设置子元素在侧轴上的排列方式(子元素多行)
| 属性值 | 含义 |
|---|---|
| flex-start | 默认值,侧轴头部开始 |
| flex-end | 侧轴尾部开始 |
| center | 侧轴居中 |
| stretch | 子元素高度平分父元素高度(需要子元素没有设置高度) |
| space-around | 平分侧轴空间 |
| space-between | 侧轴两侧贴边再平分剩余空间 |
| space-evenly | 子盒间的间隙相等 |
flex-flow
flex-direction 与 flex-wrap 属性的复合写法
son {
flex-flow: row wrap;
}
flex 布局子盒子常见属性
flex
flex 属性其实是 flex-grow、flex-shrink、flex-basis 三个属性的简写。
flex-grow 属性值为一个数字,用于设置弹性盒子的扩展比例,即盒子占剩余空间的份数,默认为 0。常见的 flex: 1 是 flex-grow 为 1。
flex-shrink 属性值为一个数字,用于设置盒子的收缩比例,当子盒子的宽度之和大于父盒子时才会收缩。
flex-basis 用于设置子盒子的初始长度。
span {
flex: 1;
}
.son {
flex: 0 0 33.33%;
}
align-self
单独设置某个子盒子在侧轴的排列方式,它会覆盖 align-items 属性。默认值为 auto,表示继承父盒子的 align-items 属性,其余属性值与 align-items 相同。
order
定义子盒子在主轴上的排列顺序。默认值为 0,值越小越靠前,可以为负数。
.son {
order: -3;
}
边栏推荐
猜你喜欢

C language - score and loop statement

clue binary tree

tracepoint: 定义函数及调用示例

Query and track multiple express tracking numbers, and filter the tracking numbers shipped at a certain time

研发医疗器械产品需要做的测试

Distributed Transactions: A Reliable Message Eventual Consistency Scheme

The big and small end problem caused by union union

查询时间内用户分布的sql语句

Typescript 命名空间
![Talk about the principle and implementation of Redis distributed lock [Ant Financial Services Three Sides]](/img/ed/dbaeab544066b5dbf19e71bee0f8c9.png)
Talk about the principle and implementation of Redis distributed lock [Ant Financial Services Three Sides]
随机推荐
Style of DataGrid in wpf
毕设——基于人脸表情的桌面交互精灵设计(分享一下成果,附上人脸表情的数据集和自己训练出来yolov5模型以及基于PYQT5运行yolov5的交互界面)
Flutter 教程之高效且精美的滚动组件Slivers (教程含源码)
MYSQL export data dictionary
【无标题】暂时没有想好叫什么名字
Personal Summary of OLTP and OLAP Issues
【js基础】js的垃圾回收机制/内存回收机制
Spark entry learning-3-SparkSQL data abstraction
String title parsing
"Public Administration" exam key points and answers
阿里云的数据库怎么提高访问速度的本地的打开的方式是www.zgysffm.com怎样的?
棋盘染色问题
Day7:面试必考选择题
云计算和云服务,云计算
【数学建模】微分方程求解 | dsolve函数 | ode45函数
MySQL5
Week 9 10 Neural Networks
【图像处理】matlab基础图像处理 | 图像载入、图像添加噪声、图像滤波、图像卷积
Leetcode78. Subset
76. The minimum cover substring