Blogger Information
Blog 20
fans 0
comment 0
visits 11668
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
flex容器中的四个属性的功能,参数,以及作用
愿情的博客
Original
586 people have browsed it

1

1.容器container

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>弹性flex容器与项目</title>
  8. <style>
  9. * {
  10. box-sizing: border-box;
  11. }
  12. :root {
  13. font-size: 10px;
  14. }
  15. body {
  16. font-size: 1.6rem;
  17. }
  18. .container {
  19. /* 转为flex布局,这个元素就叫flex/弹性容器 */
  20. display: flex;
  21. height: 20em;
  22. border: 1px solid black;
  23. }
  24. /* 项目样式:必须是flex容器得子元素 */
  25. /* flex容器中得子元素自动生成flex容器的项目,并且是行内块显示 */
  26. .container > .item {
  27. padding: 1rem;
  28. background-color: lightcyan;
  29. border: 1px solid black;
  30. }
  31. </style>
  32. </head>
  33. <body>
  34. <div class="container">
  35. <div class="item">item1</div>
  36. <div class="item">item2</div>
  37. <div class="item">item3</div>
  38. </div>
  39. </body>
  40. </html>

2.弹性项目在主轴上的排列方式

1

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>弹性项目在主轴上的排列方式</title>
  8. <style>
  9. * {
  10. box-sizing: border-box;
  11. }
  12. :root {
  13. font-size: 10px;
  14. }
  15. body {
  16. font-size: 1.6rem;
  17. }
  18. .container {
  19. /* 转为flex布局,这个元素就叫flex/弹性容器 */
  20. display: flex;
  21. /* height: 20em; */
  22. height: 100vh;
  23. border: 1px solid black;
  24. }
  25. /* 项目样式:必须是flex容器得子元素 */
  26. /* flex容器中得子元素自动生成flex容器的项目,并且是行内块显示 */
  27. .container > .item {
  28. /* padding: 1rem; */
  29. /* width: 10rem; */
  30. /* height: 5rem; */
  31. background-color: lightcyan;
  32. border: 1px solid black;
  33. }
  34. /* 1.单行容器 */
  35. .container {
  36. /* 主轴方向:默认水平,行 */
  37. /* flex-direction: row; */
  38. /* 禁止换行 */
  39. /* flex-wrap: nowrap; */
  40. /* 简化 */
  41. /* flex-flow: 主轴方向 是否换行 */
  42. /* 手机端常用的方式 */
  43. flex-flow: row nowrap;
  44. }
  45. /* 2多行容器 */
  46. .container {
  47. /* 允许换行 */
  48. /* flex-flow: row wrap; */
  49. /* 主轴垂直 */
  50. /* flex-flow: column nowrap; */
  51. flex-flow: column wrap;
  52. }
  53. .container .item:nth-of-type(1) .container .item:nth-of-type(3) {
  54. height: 8vh;
  55. }
  56. .container .item:nth-of-type(2) {
  57. height: 84vh;
  58. }
  59. </style>
  60. </head>
  61. <body>
  62. <div class="container">
  63. <div class="item">item1</div>
  64. <div class="item">item2</div>
  65. <div class="item">item3</div>
  66. <!-- <div class="item">item4</div>
  67. <div class="item">item5</div>
  68. <div class="item">item6</div>
  69. <div class="item">item7</div>
  70. <div class="item">item8</div> -->
  71. </div>
  72. </body>
  73. </html>

3.弹性项目在主轴和交叉轴上的对齐

1

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>弹性项目在主轴和交叉轴上的对齐</title>
  8. <style>
  9. * {
  10. box-sizing: border-box;
  11. }
  12. :root {
  13. font-size: 10px;
  14. }
  15. body {
  16. font-size: 1.6rem;
  17. }
  18. .container {
  19. /* 转为flex布局,这个元素就叫flex/弹性容器 */
  20. display: flex;
  21. height: 20em;
  22. border: 1px solid black;
  23. }
  24. /* 项目样式:必须是flex容器得子元素 */
  25. .container > .item {
  26. width: 10rem;
  27. height: 5rem;
  28. background-color: lightcyan;
  29. border: 1px solid black;
  30. }
  31. /* 设置项目在主轴的对齐方式的前提是:主轴上存在剩余空间 */
  32. .container {
  33. flex-flow: row nowrap;
  34. /* 一。项目在主轴的对齐方式 :justify-conten*/
  35. /* 1.将所有项目看成一个整体来处理 ,向左,向右,居中对齐*/
  36. justify-content: flex-start;
  37. justify-content: flex-end;
  38. justify-content: center;
  39. /* 2.将所有项目看成一个个独立的个体来处理 */
  40. /* 两端对齐 */
  41. justify-content: space-between;
  42. /* 分散对齐 */
  43. justify-content: space-around;
  44. /* 平均对齐 */
  45. justify-content: space-evenly;
  46. }
  47. /* 二。项目在交叉轴上的对齐方式:align-items; */
  48. .container {
  49. align-items: stretch;
  50. align-items: flex-start;
  51. align-items: flex-end;
  52. align-items: center;
  53. }
  54. </style>
  55. </head>
  56. <body>
  57. <div class="container">
  58. <div class="item">item1</div>
  59. <div class="item">item2</div>
  60. <div class="item">item3</div>
  61. <div class="item">item4</div>
  62. <!-- <div class="item">item5</div>
  63. <div class="item">item6</div>
  64. <div class="item">item7</div>
  65. <div class="item">item8</div> -->
  66. </div>
  67. </body>
  68. </html>

4.弹性项目在多行容器中的排对齐方式弹性项目在多行容器中的排对齐方式

1

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>弹性项目在多行容器中的排对齐方式</title>
  8. <style>
  9. * {
  10. box-sizing: border-box;
  11. }
  12. :root {
  13. font-size: 10px;
  14. }
  15. body {
  16. font-size: 1.6rem;
  17. }
  18. .container {
  19. /* 转为flex布局,这个元素就叫flex/弹性容器 */
  20. display: flex;
  21. height: 20rem;
  22. border: 1px solid black;
  23. }
  24. /* 项目样式:必须是flex容器得子元素 */
  25. .container > .item {
  26. width: 10rem;
  27. height: 5rem;
  28. background-color: lightcyan;
  29. border: 1px solid black;
  30. }
  31. /* 转为多行容器 */
  32. .container {
  33. flex-flow: row wrap;
  34. /* 多行容器中对齐时,主轴上是没有剩余空间的,为什么?有剩余空间就不换行 */
  35. /* 换行后,如果需要设置对齐方式,就要求交叉轴上必须要有剩余空间 */
  36. align-content: stretch;
  37. align-content: flex-start;
  38. align-content: flex-end;
  39. align-content: center;
  40. /* 看成个体 */
  41. /* 二段对齐 */
  42. align-content: space-between;
  43. /* 分散对齐 */
  44. align-content: space-around;
  45. /* 平均对齐 */
  46. align-content: space-evenly;
  47. }
  48. </style>
  49. </head>
  50. <body>
  51. <div class="container">
  52. <div class="item">item1</div>
  53. <div class="item">item2</div>
  54. <div class="item">item3</div>
  55. <div class="item">item4</div>
  56. <div class="item">item5</div>
  57. <div class="item">item6</div>
  58. <div class="item">item7</div>
  59. <div class="item">item8</div>
  60. <div class="item">item9</div>
  61. <div class="item">item10</div>
  62. <div class="item">item11</div>
  63. <div class="item">item12</div>
  64. </div>
  65. </body>
  66. </html>
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!