当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

Tensorboard的使用 ---- SummaryWriter类(pytorch版)

如何批量导入文件,并全部自定义重命名为相同文件名

温故知新—Activity的五种启动模式

Hundreds of billions, large-scale: performance tuning practice of Tencent's super-large Apache Pulsar cluster

Flutter 教程之高效且精美的滚动组件Slivers (教程含源码)

28.异常检测

Sqlmap + dnslog injection of repetition

The difference between classification, object detection, semantic segmentation, and instance segmentation

Why do big Internet companies keep hiring while frantically laying off staff?

【图像处理】matlab基础图像处理 | 图像载入、图像添加噪声、图像滤波、图像卷积
随机推荐
TSF Microservice Governance Combat Series (2) - Service Routing
VSCode已经设置过为中文但变成英文的解决办法
stack-queue
C language - function
仿记事本;QFile
Unity mouse cursor usage learning
为什么互联网大厂一边疯狂裁员,一边不停招聘?
Lecture 84 Biweekly t4 6144 and Lecture 305 t4 6138
76. 最小覆盖子串
TSF微服务治理实战系列(二)——服务路由
LVS:NAT模式详解
线索二叉树
C language framework FreeSwitch custom event introduction and usage example
查询跟踪多家快递单号,筛选某一时间发货的单号
云计算和云服务,云计算
Week 8 Generative Adversarial Networks
Why do big Internet companies keep hiring while frantically laying off staff?
【js基础】闭包的几种情况(代码)
Postman显示验证码图片(base64字符串)
Session 和 Cookie 使用