博客列表 >flex--弹性布局

flex--弹性布局

路亚
路亚原创
2020年04月10日 16:10:07673浏览
总结:今天学习flex 弹性布局,感觉听蒙了,经过课程回放,稍微消化了一点点,还是不够熟练。本来准备想简单的去模仿一个别的站点的页面,结果无从下手

flex 布局概述

1. flex 是什么

  • flex 是 Flexible Box 的缩写,意为弹性布局
  • flex 2009 年就已出现,浏览器兼容性很好,请放心使用

2. flex 解决了什么问题

  • 块元素的垂直居中, flex 可以轻松解决
  • 元素大小在容器中的自动伸缩,以适应容器的变化,特别适合移动端布局

3. flex 项目的布局方向是什么

  • 一个物体在一个平面中, 要么水平排列, 要么垂直排列, flex 借鉴了这个思想
  • flex 是一维布局, 项目任何时候只能沿一个方向排列,要么水平, 要么垂直
  • flex 项目排列的方向, 称为主轴, 水平和垂直二种
  • 与主轴垂直的称为交叉轴(有的教程也称之为副轴/侧轴)

4. flex 布局中常用术语有哪些(三个二)

序号 简记 术语
1 二成员 容器和项目(container / item)
2 二根轴 主轴与交叉轴(main-axis / cross-axis)
3 二根线 起始线与结束线(flex-start / flex-end)

5.flex 容器属性有哪些

序号 属性 描述
1 flex-direction 设置容器中的主轴方向: 行/水平方向, 列/垂直方向
2 flex-wrap 是否允许创建多行容器,即 flex 项目一行排列不下时, 是否允许换行
3 flex-flow 简化 flex-direction, flex-wrap 属性
4 justify-content 设置 flex 项目在主轴上对齐方式
5 align-items 设置 flex 项目在交叉轴上对齐方式
6 align-content 多行容器中,项目在交叉轴上的对齐方式

6. flex 项目属性有哪些

序号 属性 描述
1 flex-basis 项目宽度: 项目分配主轴剩余空间之前, 项目所占据的主轴空间宽度
2 flex-grow 项目的宽度扩展: 将主轴上的剩余空间按比例分配给指定项目
3 flex-shrink 项目的宽度收缩: 将项目上多出空间按比例在项目间进行缩减
4 flex 是上面三个属性的简化缩写: flex: flex-grow flex-shrink flex-basis
5 align-self 单独自定义某个项目在交叉轴上的对齐方式
6 order 自定义项目在主轴上的排列顺序,默认为 0,书写顺序,值越小位置越靠前

flex 容器与项目

1. display属性

序号 属性值 描述 备注
1 flex; 创建 flex 块级容器 内部子元素自动成为 flex 项目
2 inline-flex; 创建 flex 行内容器 内部子元素自动成为 flex 项目

2. flex 容器与项目特征

序号 容器/项目 默认行为
1 容器主轴 水平方向
2 项目排列 沿主轴起始线排列(当前起始线居左)
3 项目类型 自动转换”行内块级”元素,不管之前是什么类型
4 容器主轴空间不足时 项目自动收缩尺寸以适应空间变化,不会换行显示
5 容器主轴存在未分配空间时 项目保持自身大小不会放大并充满空间

1 效果展示

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>Document</title>
  7. <style>
  8. /* 容器 */
  9. .container {
  10. width: 300px;
  11. height: 150px;
  12. display: flex;
  13. /* display: inline-flex; */
  14. }
  15. /* 子元素 */
  16. .item {
  17. width: 100px;
  18. height: 50px;
  19. background-color: fuchsia;
  20. font-size: 1.5rem;
  21. }
  22. </style>
  23. </head>
  24. <body>
  25. <div class="container">
  26. <div class="item">1</div>
  27. <div class="item">2</div>
  28. <div class="item">3</div>
  29. <div class="item">4</div>
  30. </div>
  31. <div class="container">
  32. <div class="item">1</div>
  33. <div class="item">2</div>
  34. <div class="item">3</div>
  35. <div class="item">4</div>
  36. </div>
  37. </body>
  38. </html>

flex 容器主轴方向

1. flex-direction属性

序号 属性值 描述
1 row默认值 主轴水平: 起始线居中,项目从左到右显示
2 row-reverse 主轴水平:起始线居右, 项目从右向左显示
3 column 主轴垂直: 起始线居上,项目从上向下显示
4 column-reverse 主轴垂直: 起始线居下,项目从下向上显示

2 效果展示

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>主轴方向</title>
  7. <style>
  8. /* 容器 */
  9. .container {
  10. width: 300px;
  11. height: 150px;
  12. display: flex;
  13. /* display: inline-flex; */
  14. }
  15. .container {
  16. flex-direction: row;
  17. flex-direction: row-reverse;
  18. flex-direction: column;
  19. flex-direction: column-reverse;
  20. }
  21. /* 子元素 */
  22. .item {
  23. width: 100px;
  24. height: 50px;
  25. background-color: fuchsia;
  26. font-size: 1.5rem;
  27. }
  28. </style>
  29. </head>
  30. <body>
  31. <div class="container">
  32. <div class="item">1</div>
  33. <div class="item">2</div>
  34. <div class="item">3</div>
  35. <div class="item">4</div>
  36. </div>
  37. </body>
  38. </html>

flex 容器主轴项目换行

1. flex-wrap属性

序号 属性值 描述
1 nowrap默认值 项目不换行: 单行容器
2 wrap 项目换行: 多行容器,第一行在上方
3 wrap-reverse 项目换行: 多行容器,第一行在下方

3 效果展示

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>主轴方向</title>
  7. <style>
  8. /* 容器 */
  9. .container {
  10. width: 300px;
  11. height: 150px;
  12. display: flex;
  13. /* display: inline-flex; */
  14. }
  15. .container {
  16. flex-direction: row;
  17. /* flex-direction: row-reverse; */
  18. /* flex-direction: column; */
  19. /* flex-direction: column-reverse; */
  20. }
  21. .container {
  22. flex-wrap: wrap;
  23. flex-wrap: nowrap;
  24. flex-wrap: wrap-reverse;
  25. }
  26. /* 子元素 */
  27. .item {
  28. width: 100px;
  29. height: 50px;
  30. background-color: fuchsia;
  31. font-size: 1.5rem;
  32. }
  33. </style>
  34. </head>
  35. <body>
  36. <div class="container">
  37. <div class="item">1</div>
  38. <div class="item">2</div>
  39. <div class="item">3</div>
  40. <div class="item">4</div>
  41. </div>
  42. </body>
  43. </html>

flex 容器主轴与项目换行简写

1. flex-flow属性

  • flex-flow是属性flex-directionflex-wrap的简写
  • 语法: flex-flow: flex-direction flex-wrap
属性值 描述
row nowrap默认值 主轴水平, 项目不换行

4 以后推荐只用它

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>主轴方向是否换行的简写</title>
  7. <style>
  8. /* 容器 */
  9. .container {
  10. width: 300px;
  11. height: 150px;
  12. display: flex;
  13. /* display: inline-flex; */
  14. }
  15. .container {
  16. flex-flow: row nowrap;
  17. flex-flow: row wrap;
  18. flex-flow: column nowrap;
  19. flex-flow: column wrap;
  20. }
  21. /* 子元素 */
  22. .item {
  23. width: 100px;
  24. height: 50px;
  25. background-color: fuchsia;
  26. font-size: 1.5rem;
  27. }
  28. </style>
  29. </head>
  30. <body>
  31. <div class="container">
  32. <div class="item">1</div>
  33. <div class="item">2</div>
  34. <div class="item">3</div>
  35. <div class="item">4</div>
  36. </div>
  37. </body>
  38. </html>

flex 容器主轴项目对齐

1. justify-content属性

当容器中主轴方向上存在剩余空间时, 该属性才有意义

序号 属性值 描述
1 flex-start默认 所有项目与主轴起始线对齐
2 flex-end 所有项目与主轴终止线对齐
3 center 所有项目与主轴中间线对齐: 居中对齐
4 space-between 两端对齐: 剩余空间在头尾项目之外的项目间平均分配
5 space-around 分散对齐: 剩余空间在每个项目二侧平均分配
6 space-evenly 平均对齐: 剩余空间在每个项目之间平均分配

5

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>主轴方向对齐方式</title>
  7. <style>
  8. /* 容器 */
  9. .container {
  10. width: 300px;
  11. height: 150px;
  12. display: flex;
  13. /* display: inline-flex; */
  14. }
  15. .container {
  16. justify-content: flex-start;
  17. justify-content: flex-end;
  18. justify-content: center;
  19. justify-content: space-around;
  20. /* justify-content: space-between; */
  21. justify-content: space-evenly;
  22. }
  23. /* 子元素 */
  24. .item {
  25. width: 50px;
  26. height: 50px;
  27. background-color: fuchsia;
  28. font-size: 1.5rem;
  29. }
  30. </style>
  31. </head>
  32. <body>
  33. <div class="container">
  34. <div class="item">1</div>
  35. <div class="item">2</div>
  36. <div class="item">3</div>
  37. <div class="item">4</div>
  38. </div>
  39. </body>
  40. </html>

flex 容器交叉轴项目对齐

1. align-items属性

  • 该属性仅适用于: 单行容器
  • 当容器中交叉轴方向上存在剩余空间时, 该属性才有意义
序号 属性值 描述
1 flex-start默认 与交叉轴起始线对齐
2 flex-end 与交叉轴终止线对齐
3 center 与交叉轴中间线对齐: 居中对齐

6

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>交叉轴上对齐方式</title>
  7. <style>
  8. /* 容器 */
  9. .container {
  10. width: 300px;
  11. height: 150px;
  12. display: flex;
  13. /* display: inline-flex; */
  14. }
  15. .container {
  16. flex-flow: word nowrap;
  17. align-items: flex-start;
  18. align-items: flex-end;
  19. align-items: center;
  20. }
  21. /* 子元素 */
  22. .item {
  23. width: 50px;
  24. height: 50px;
  25. background-color: fuchsia;
  26. font-size: 1.5rem;
  27. }
  28. </style>
  29. </head>
  30. <body>
  31. <div class="container">
  32. <div class="item">1</div>
  33. <div class="item">2</div>
  34. <div class="item">3</div>
  35. <div class="item">4</div>
  36. </div>
  37. </body>
  38. </html>

flex 多行容器交叉轴项目对齐

1. align-content属性

  • 该属性仅适用于: 多行容器
  • 多行容器中, 交叉轴会有多个项目, 剩余空间在项目之间分配才有意义
序号 属性值 描述
1 stretch默认 项目拉伸占据整个交叉轴
1 flex-start 所有项目与交叉轴起始线(顶部)对齐
2 flex-end 所有项目与交叉轴终止线对齐
3 center 所有项目与交叉轴中间线对齐: 居中对齐
4 space-between 两端对齐: 剩余空间在头尾项目之外的项目间平均分配
5 space-around 分散对齐: 剩余空间在每个项目二侧平均分配
6 space-evenly 平均对齐: 剩余空间在每个项目之间平均分配

提示: 多行容器中通过设置flex-wrap: wrap | wrap-reverse实现

7

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>多行容器对齐方式</title>
  7. <style>
  8. /* 容器 */
  9. .container {
  10. width: 300px;
  11. height: 150px;
  12. display: flex;
  13. /* display: inline-flex; */
  14. }
  15. .container {
  16. flex-flow: row wrap;
  17. /* 自动拉伸align-content: stretch; */
  18. align-content: stretch;
  19. align-content: space-evenly;
  20. align-content: space-between;
  21. align-content: space-around;
  22. }
  23. /* 子元素 */
  24. .item {
  25. width: 50px;
  26. height: 50px;
  27. background-color: fuchsia;
  28. font-size: 1.5rem;
  29. }
  30. </style>
  31. </head>
  32. <body>
  33. <div class="container">
  34. <div class="item">1</div>
  35. <div class="item">2</div>
  36. <div class="item">3</div>
  37. <div class="item">4</div>
  38. <div class="item">5</div>
  39. <div class="item">6</div>
  40. <div class="item">7</div>
  41. <div class="item">8</div>
  42. <div class="item">9</div>
  43. </div>
  44. </body>
  45. </html>

flex 项目交叉轴单独对齐

1. align-self属性

  • 该属性可覆盖容器的align-items, 用以自定义某个项目的对齐方式
序号 属性值 描述
1 auto默认值 继承 align-items 属性值
2 flex-start 与交叉轴起始线对齐
3 flex-end 与交叉轴终止线对齐
4 center 与交叉轴中间线对齐: 居中对齐
5 stretch 在交叉轴方向上拉伸
6 baseline 与基线对齐(与内容相关用得极少)

8

```h<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>xiangmushun项目顺序对齐方式</title>
<style>
/ 容器 /
.container {
width: 300px;
height: 150px;
display: flex;
/ display: inline-flex; /
}

.container {
}

/ 子元素 /
.item {
width: 50px;
height: 50px;
background-color: fuchsia;
font-size: 1.5rem;
order: 0;
}
.item:first-of-type {
order: 4;
background-color: greenyellow;
}
.item:nth-of-type(2) {
order: 3;
background-color: rgb(6, 221, 236);
}
.item:nth-of-type(3) {
order: 2;
background-color: mediumblue;
}
.item:last-of-type {
background-color: mediumturquoise;
}
</style>
</head>
<body>
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
</div>
</body>
</html>
tml
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>xiangmushun项目顺序对齐方式</title>
<style>
/ 容器 /
.container {
width: 300px;
height: 150px;
display: flex;
/ display: inline-flex; /
}

.container {
}

/ 子元素 /
.item {
width: 50px;
height: 50px;
background-color: fuchsia;
font-size: 1.5rem;
order: 0;
}
.item:first-of-type {
order: 4;
background-color: greenyellow;
}
.item:nth-of-type(2) {
order: 3;
background-color: rgb(6, 221, 236);
}
.item:nth-of-type(3) {
order: 2;
background-color: mediumblue;
}
.item:last-of-type {
background-color: mediumturquoise;
}
</style>
</head>
<body>
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
</div>
</body>
</html>

  1. ![](https://img.php.cn/upload/image/809/359/444/1586505440328047.png)
  2. # flex 项目放大因子
  3. ## 1. `flex-grow`属性
  4. - 在容器主轴上存在剩余空间时, `flex-grow`才有意义
  5. - 该属性的值,称为**放大因子**, 常见的属性值如下:
  6. | 序号 | 属性值 | 描述 |
  7. | ---- | --------- | -------------------- |
  8. | 1 | `0`默认值 | 不放大,保持初始值 |
  9. | 2 | `initial` | 设置默认值,与`0`等效 |
  10. | 3 | `n` | 放大因子: 正数 |
  11. ### 9
  12. ```html
  13. <!DOCTYPE html>
  14. <html lang="en">
  15. <head>
  16. <meta charset="UTF-8" />
  17. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  18. <title>xiangmushun项目独立对齐方式</title>
  19. <style>
  20. /* 容器 */
  21. .container {
  22. width: 300px;
  23. height: 150px;
  24. display: flex;
  25. /* display: inline-flex; */
  26. }
  27. .container {
  28. }
  29. /* 子元素 */
  30. .item {
  31. width: 50px;
  32. height: 50px;
  33. background-color: fuchsia;
  34. font-size: 1.5rem;
  35. align-self: auto;
  36. }
  37. .item:first-of-type {
  38. height: inherit;
  39. align-self: stretch;
  40. background-color: greenyellow;
  41. }
  42. .item:nth-of-type(2) {
  43. align-self: flex-end;
  44. background-color: rgb(6, 221, 236);
  45. }
  46. .item:nth-of-type(3) {
  47. align-self: flex-start;
  48. background-color: mediumblue;
  49. }
  50. .item:last-of-type {
  51. align-self: center;
  52. background-color: red;
  53. }
  54. </style>
  55. </head>
  56. <body>
  57. <div class="container">
  58. <div class="item">1</div>
  59. <div class="item">2</div>
  60. <div class="item">3</div>
  61. <div class="item">4</div>
  62. </div>
  63. </body>
  64. </html>

flex 项目收缩因子

1. flex-shrink属性

  • 当容器主轴 “空间不足” 且 “禁止换行” 时, flex-shrink才有意义
  • 该属性的值,称为收缩因子, 常见的属性值如下:
序号 属性值 描述
1 1默认值 允许项目收缩
2 initial 设置初始默认值,与 1 等效
3 0 禁止收缩,保持原始尺寸
4 n 收缩因子: 正数

10

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>xiangmushun项目放大因子</title>
  7. <style>
  8. /* 容器 */
  9. .container {
  10. width: 300px;
  11. height: 150px;
  12. display: flex;
  13. /* display: inline-flex; */
  14. }
  15. .container {
  16. }
  17. /* 子元素 */
  18. .item {
  19. width: 50px;
  20. height: 50px;
  21. background-color: fuchsia;
  22. font-size: 1.5rem;
  23. flex-grow: 0;
  24. flex-grow: initial;
  25. /* flex-grow: 1; */
  26. /* flex-grow: 1; */
  27. }
  28. .item:first-of-type {
  29. flex-grow: 1;
  30. background-color: greenyellow;
  31. }
  32. .item:nth-of-type(2) {
  33. flex-grow: 2;
  34. background-color: rgb(6, 221, 236);
  35. }
  36. .item:last-of-type {
  37. flex-grow: 3;
  38. background-color: red;
  39. }
  40. </style>
  41. </head>
  42. <body>
  43. <div class="container">
  44. <div class="item">1</div>
  45. <div class="item">2</div>
  46. <div class="item">3</div>
  47. </div>
  48. </body>
  49. </html>

flex 项目计算尺寸

1. flex-basis属性

  • 在分配多余空间之前,项目占据的主轴空间
  • 浏览器根据这个属性,计算主轴是否有多余空间
  • 该属性会覆盖项目原始大小(width/height)
  • 该属性会被项目的min-width/min-height值覆盖
序号 属性值 描述
1 auto 默认值: 项目原来的大小
2 px 像素
3 % 百分比

优先级: 项目大小 < flex-basis < min-width/height

11

```html
<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>项目收缩因子</title>
<style>
/ 容器 /
.container {
width: 180px;
height: 150px;
display: flex;
flex-flow: row nowrap;
/ display: inline-flex; /
}

  1. .container {
  2. }
  3. /* 子元素 */
  4. .item {
  5. width: 100px;
  6. height: 50px;
  7. background-color: fuchsia;
  8. font-size: 1.5rem;
  9. flex-shrink: 0;
  10. }
  11. .item:first-of-type {
  12. background-color: greenyellow;
  13. flex-shrink: 1;
  14. }
  15. .item:nth-of-type(2) {
  16. flex-shrink: 2;
  17. background-color: rgb(6, 221, 236);
  18. }
  19. .item:last-of-type {
  20. flex-shrink: 3;
  21. background-color: red;
  22. }
  23. </style>

</head>
<body>
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
</body>
</html>

  1. ![](https://img.php.cn/upload/image/179/383/363/1586505561982208.png)
  2. # flex 项目缩放的简写
  3. ## 1. `flex`属性
  4. - 项目放大,缩小与计算尺寸,对于项目非常重要,也很常用
  5. - 每次都要写这三个属性,非常的麻烦,且没有必要
  6. - `flex`属性,可以将以上三个属性进行简化:
  7. - 语法: `flex: flex-grow flex-shrink flex-basis`
  8. ### 1.1 三值语法
  9. | 序号 | 属性值 | 描述 |
  10. | ---- | ------------------ | ------------- |
  11. | 1 | 第一个值: 整数 | `flex-grow` |
  12. | 2 | 第二个值: 整数 | `flex-shrink` |
  13. | 3 | 第三个值: 有效宽度 | `flex-basis` |
  14. 举例:
  15. | 序号 | 案例 | 描述 |
  16. | ---- | ----------------- | ------------------------------- |
  17. | 1 | `flex: 0 1 auto` | 默认值: 不放大,可收缩, 初始宽度 |
  18. | 2 | `flex: 1 1 auto` | 项目自动放大或收缩适应容器 |
  19. | 3 | `flex: 0 0 100px` | 按计算大小填充到容器中 |
  20. ### 1.2 双值语法
  21. | 序号 | 属性值 | 描述 |
  22. | ---- | ------------------ | ------------ |
  23. | 1 | 第一个值: 整数 | `flex-grow` |
  24. | 3 | 第二个值: 有效宽度 | `flex-basis` |
  25. 举例:
  26. | 案例 | 描述 |
  27. | --------------- | ------------------------------- |
  28. | `flex: 0 180px` | 禁止放大,按计算大小填充到容器中 |
  29. ### 1.3 单值语法
  30. | 序号 | 属性值 | 描述 |
  31. | ---- | -------- | ----------------------- |
  32. | 1 | 整数 | `flex-grow` |
  33. | 2 | 有效宽度 | `flex-basis` |
  34. | 3 | 关键字 | `initial | auto | none` |
  35. 举例:
  36. | 序号 | 案例 | 描述 |
  37. | ---- | ------------- | ----------------- |
  38. | 1 | `flex: 1` | `flex: 1 1 auto` |
  39. | 2 | `flex: 180px` | `flex: 1 1 180px` |
  40. | 3 | `initial` | `flex: 0 1 auto` |
  41. | 4 | `auto` | `flex: 1 1 auto` |
  42. | 5 | `none` | `flex: 0 0 auto` |
  43. > 推荐使用`flex`, 就像推荐使用`flex-grow`设置主轴与换行一样
  44. ```html
  45. <!DOCTYPE html>
  46. <html lang="en">
  47. <head>
  48. <meta charset="UTF-8" />
  49. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  50. <title>项目收缩因子</title>
  51. <style>
  52. /* 容器 */
  53. .container {
  54. width: 300px;
  55. height: 150px;
  56. display: flex;
  57. /* display: inline-flex; */
  58. }
  59. .container {
  60. }
  61. /* 子元素 */
  62. .item {
  63. width: 100px;
  64. height: 50px;
  65. background-color: fuchsia;
  66. font-size: 1.5rem;
  67. }
  68. .item:first-of-type {
  69. flex: 0 1 auto;
  70. flex: 1 1 auto;
  71. /* flex: 0 1 80px; */
  72. background-color: greenyellow;
  73. }
  74. .item:nth-of-type(2) {
  75. flex: 0 100px;
  76. background-color: rgb(6, 221, 236);
  77. }
  78. .item:last-of-type {
  79. flex: auto;
  80. /* flex: 1; */
  81. flex: 0;
  82. /* flex: none; */
  83. /* flex: 0 0 auto; */
  84. flex: 0 0 150px;
  85. background-color: red;
  86. }
  87. </style>
  88. </head>
  89. <body>
  90. <div class="container">
  91. <div class="item">1</div>
  92. <div class="item">2</div>
  93. <div class="item">3</div>
  94. </div>
  95. </body>
  96. </html>

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议