当前位置:网站首页>flex layout (flexible layout)
flex layout (flexible layout)
2022-08-02 06:31:00 【Pillow said he didn't want to wake up】
一、Pros and cons of traditional layouts:
1、兼容性好
2、布局繁琐
3、局限性,不能在移动端很好的布局
二、flex布局的优缺点:
1、操作方便,布局即为简单,移动端应用广泛
2、PCSegment browser support is poor
3、Ie 11或更低版本,不支持或仅部分支持
三、flex布局原理
flex:The first is that either can be specified as a flex layout
1、When our parent box is set to flex布局以后,子元素的dloat、clear和vetical-alignAttributes will be aged
2、伸缩布局=弹性布局=flex布局
总结原理:就是通过给父盒子添加flex属性,来控制子盒子的位置和排列方式
四、Common container properties
以下6个属性设置在容器上.
- flex-direction
- flex-wrap
- flex-flow
- justify-content
- align-items
- align-content
4.1、flex-direction
属性决定主轴的方向(即项目的排列方向).
.box {
flex-direction: row 、 row-reverse 、 column 、 column-reverse;
}
它可能有4个值.
row
(默认值):主轴为水平方向,起点在左端.row-reverse
:主轴为水平方向,起点在右端.column
:主轴为垂直方向,起点在上沿.column-reverse
:主轴为垂直方向,起点在下沿.
4.2 flex-wrap属性
默认情况下,项目都排在一条线(又称"轴线")上.flex-wrap
属性定义,如果一条轴线排不下,如何换行.
.box{
flex-wrap: nowrap wrap wrap-reverse;
}
(1)nowrap
(默认):不换行.
(2)wrap
:换行,第一行在上方.
(3)wrap-reverse
:换行,第一行在下方.
4.3 flex-flow
flex-flow
属性是flex-direction
属性和flex-wrap
属性的简写形式,默认值为row nowrap
.
.box {
flex-flow: <flex-direction> || <flex-wrap>;
}
4.4 justify-content属性
justify-content
属性定义了项目在主轴上的对齐方式.
.box {
justify-content: flex-start flex-end center space-between space-around;
}
它可能取5个值,具体对齐方式与轴的方向有关.下面假设主轴为从左到右.
flex-start
(默认值):左对齐flex-end
:右对齐center
: 居中space-between
:两端对齐,项目之间的间隔都相等.space-around
:每个项目两侧的间隔相等.所以,项目之间的间隔比项目与边框的间隔大一倍.
4.5 align-items属性
align-items
属性定义项目在交叉轴上如何对齐.
.box {
align-items: flex-start flex-end center baseline stretch;
}
它可能取5个值.具体的对齐方式与交叉轴的方向有关,下面假设交叉轴从上到下.
flex-start
:交叉轴的起点对齐.flex-end
:交叉轴的终点对齐.center
:交叉轴的中点对齐.baseline
: 项目的第一行文字的基线对齐.stretch
(默认值):如果项目未设置高度或设为auto,将占满整个容器的高度.
4.6 align-content属性
align-content
属性定义了多根轴线的对齐方式.如果项目只有一根轴线,该属性不起作用.
.box {
align-content: flex-start flex-end center space-between space-around stretch;
}
该属性可能取6个值.
flex-start
:与交叉轴的起点对齐.flex-end
:与交叉轴的终点对齐.center
:与交叉轴的中点对齐.space-between
:与交叉轴两端对齐,轴线之间的间隔平均分布.space-around
:每根轴线两侧的间隔都相等.所以,轴线之间的间隔比轴线与边框的间隔大一倍.stretch
(默认值):轴线占满整个交叉轴.
五、项目的属性
以下6个属性设置在项目上.
order
flex-grow
flex-shrink
flex-basis
flex
align-self
5.1 order属性
order
属性定义项目的排列顺序.数值越小,排列越靠前,默认为0.
.item {
order: <integer>;
}
5.2 flex-grow属性
flex-grow
属性定义项目的放大比例,默认为0
,即如果存在剩余空间,也不放大.
.item {
flex-grow: <number>; /* default 0 */
}
如果所有项目的flex-grow
属性都为1,则它们将等分剩余空间(如果有的话).如果一个项目的flex-grow
属性为2,其他项目都为1,则前者占据的剩余空间将比其他项多一倍.
5.3 flex-shrink属性
flex-shrink
属性定义了项目的缩小比例,默认为1,即如果空间不足,该项目将缩小.
.item {
flex-shrink: <number>; /* default 1 */
}
如果所有项目的flex-shrink
属性都为1,当空间不足时,都将等比例缩小.如果一个项目的flex-shrink
属性为0,其他项目都为1,则空间不足时,前者不缩小.
负值对该属性无效.
5.4 flex-basis属性
flex-basis
属性定义了在分配多余空间之前,项目占据的主轴空间(main size).浏览器根据这个属性,计算主轴是否有多余空间.它的默认值为auto
,即项目的本来大小.
.item {
flex-basis: <length> | auto; /* default auto */
}
它可以设为跟width
或height
属性一样的值(比如350px),则项目将占据固定空间.
5.5 flex属性
flex
属性是flex-grow
, flex-shrink
和 flex-basis
的简写,默认值为0 1 auto
.后两个属性可选.
.item {
flex: none | [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ]
}
该属性有两个快捷值:auto
(1 1 auto
) 和 none (0 0 auto
).
建议优先使用这个属性,而不是单独写三个分离的属性,因为浏览器会推算相关值.
5.6 align-self属性
align-self
属性允许单个项目有与其他项目不一样的对齐方式,可覆盖align-items
属性.默认值为auto
,表示继承父元素的align-items
属性,如果没有父元素,则等同于stretch
.
.item {
align-self: auto 、 flex-start 、 flex-end 、 center 、 baseline 、 stretch;
}
该属性可能取6个值,除了auto,其他都与align-items属性完全一致.
边栏推荐
- 软件测试的需求人才越来越多,为什么大家还是不太愿意走软件测试的道路?
- Meta公司新探索 | 利用Alluxio数据缓存降低Presto延迟
- Install and use Google Chrome
- 浏览器的onload事件
- 关于web应用的目录结构
- Mysql common commands
- 关于鸿蒙系统 JS UI 框架源码的分析
- Redis database
- el-input can only input integers (including positive numbers, negative numbers, 0) or only integers (including positive numbers, negative numbers, 0) and decimals
- pytorch常用函数
猜你喜欢
淘系资深工程师整理的300+项学习资源清单(2021最新版)
Automated operation and maintenance tools - ansible, overview, installation, module introduction
驱动页面性能优化的3个有效策略
Browser onload event
虚拟现实房产展示系统提前预见未来装修效果
Redis集群模式
Differences between i++ and ++i in loops in C language
5款经典代码阅读器的使用方案对比
leetcode一步解决链表合并问题
Review: image saturation calculation formula and image signal-to-noise (PSNR) ratio calculation formula
随机推荐
pytorch基本操作:使用神经网络进行分类任务
说好的女程序员做测试有优势?面试十几家,被面试官虐哭~~
Introduction to Grid Layout
swinIR论文阅读笔记
5年在职经验之谈:2年功能测试、3年自动化测试,从入门到不可自拔...
Introduction to coredns
Navicat new database
golang泛型
classSR论文阅读笔记
Integrate ssm (1)
apisix-Getting Started
goroutine (coroutine) in go language
H5 access payment process - WeChat payment & Alipay payment
About the directory structure of the web application
无代码生产新模式探索
165.比较版本号
测试环境要多少?从成本与效率说起
浏览器的onload事件
网安学习-内网渗透4
金山云团队分享 | 5000字读懂Presto如何与Alluxio搭配