当前位置:网站首页>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个属性设置在项目上.
orderflex-growflex-shrinkflex-basisflexalign-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属性完全一致.
边栏推荐
- 保证家里和企业中的WIFI安全-附AC与AP组网实验
- 非关系型数据库MongoDB的特点及安装
- 软件测试在职2年跳槽4次,你还在怪老板不给你涨薪?
- Matlab paper illustration drawing template No. 41 - bubble chart (bubblechart)
- Meta公司新探索 | 利用Alluxio数据缓存降低Presto延迟
- 机器学习——支持向量机原理
- eggjs controller层调用controller层解决方案
- 国际顶会OSDI首度收录淘宝系统论文,端云协同智能获大会主旨演讲推荐
- 18 years of programmer career, read more than 200 programming books, pick out some essence to share with you
- MySQL implements sorting according to custom (specified order)
猜你喜欢

Introduction to coredns

leetcode一步解决链表合并问题

Matlab paper illustration drawing template No. 41 - bubble chart (bubblechart)

Meta公司新探索 | 利用Alluxio数据缓存降低Presto延迟

机器学习——支持向量机原理

国际顶会OSDI首度收录淘宝系统论文,端云协同智能获大会主旨演讲推荐

深度学习——CNN实现MNIST手写数字的识别

Use the browser's local storage to realize the function of remembering the user name

【合集- 行业解决方案】如何搭建高性能的数据加速与数据编排平台

The company does not pay attention to software testing, and the new Ali P8 has written a test case writing specification for us
随机推荐
Detailed explanation of the software testing process (mind map) of the first-tier manufacturers
Timing task library in the language use Cron, rounding
Linux CentOS8安装Redis6
MySQL implements sorting according to custom (specified order)
字节面试题:如何保证缓存和数据库的一致性
Three methods of importing sql files in MySQL
C语言基础知识梳理总结:零基础入门请看这一篇
leetcode每天5题-Day04
What are the ways to improve software testing capabilities?After reading this article, it will take you up a notch
ELK log analysis system
网安学习-内网渗透4
Brush LeetCode topic series - 10. Regular expression match
golang generics
面试官:设计“抖音”直播功能测试用例吧
保证家里和企业中的WIFI安全-附AC与AP组网实验
C language: Check for omissions and fill in vacancies (3)
卸载redis
在腾讯做外包测试的那些日子.....
navicat connects to MySQL and reports an error: 1045 - Access denied for user 'root'@'localhost' (using password YES)
【解决】RESP.app 连接不上redis