Blogger Information
Blog 43
fans 0
comment 0
visits 30468
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
flex容器
橙絮圆
Original
478 people have browsed it

flex容器


作业内容:实例演示flex容器与项目中常用的属性,并写出功能


  • flex-flow
    主轴方向是否换行

    • 效果图
      flex-flow
    • 代码

      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. /* flex-flow */
      10. :root {
      11. font-size: 10px;
      12. }
      13. body {
      14. font-size: 1.6rem;
      15. }
      16. .container {
      17. /* 转为flex容器,这样就可以使得flex特征进行布局了 */
      18. display: flex;
      19. border: 1px dashed;
      20. /* flex-direction:row; */
      21. width:40rem;
      22. background-color:wheat;
      23. /* flex-wrap: wrap; */
      24. /* flex-flow:主轴方向 是否换行; */
      25. /* 有换行:多行容器 */
      26. /* 多行容器中,每一行都有一根主轴 */
      27. flex-flow:row wrap;
      28. }
      29. /* flex项目必须是flex容器的直直接子元素 */
      30. .container > .item {
      31. /* 项目默认可收缩但不会放大 */
      32. padding: 1rem;
      33. height: 10rem;
      34. background-color: lightcyan;
      35. border: 1px solid;
      36. }
      37. /* 1.任何一个可视元素,添加display:flex后都可转为flex弹性容器 */
      38. /* 2.flex弹性容器内的直接子元素称之为flex项目,它是真正的布局目标对象 */
      39. </style>
      40. </head>
      41. <body>
      42. <div class="container">
      43. <div class="item">item1</div>
      44. <div class="item">item2</div>
      45. <div class="item">item3</div>
      46. <div class="item">item4</div>
      47. <div class="item">item5</div>
      48. <div class="item">item6</div>
      49. <div class="item">item7</div>
      50. <div class="item">item8</div>
      51. </html>

  • justify-content:
    在主轴上的对齐方式
    flex-start 左对齐
    flex-end 右对齐
    space-between 两端对齐
    space-around 分散对齐
    space-evenly 平均对齐
    • 效果图
      justify-content
    • 代码
      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. :root {
      10. font-size: 10px;
      11. }
      12. body {
      13. font-size: 1.6rem;
      14. }
      15. .container {
      16. display: flex;
      17. border: 1px dashed;
      18. height: 20rem;
      19. justify-content: flex-start;
      20. justify-content: flex-end;
      21. justify-content: center;
      22. /* 两端对齐 */
      23. justify-content: space-between;
      24. /* 分散对齐 */
      25. justify-content:space-around;
      26. /* 平均对齐 */
      27. justify-content: space-evenly;
      28. }
      29. .container > .item {
      30. padding: 1rem;
      31. height: 10rem;
      32. background-color: lightcyan;
      33. border: 1px solid;
      34. }
      35. </style>
      36. </head>
      37. <body>
      38. <div class="container">
      39. <div class="item">item1</div>
      40. <div class="item">item2</div>
      41. <div class="item">item3</div>
      42. <div class="item">item4</div>
      43. </html>

  • align-items
    交叉对齐
    stretch拉伸
    flex-start顶端对齐
    flex-end 底端对齐
    center 居中对齐
    • 效果图
      align-items
    • 代码
      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. :root {
      10. font-size: 10px;
      11. }
      12. body {
      13. font-size: 1.6rem;
      14. }
      15. .container {
      16. display: flex;
      17. border: 1px dashed;
      18. height: 20rem;
      19. justify-content: flex-start;
      20. justify-content: flex-end;
      21. justify-content: center;
      22. /* 两端对齐 */
      23. justify-content: space-between;
      24. /* 分散对齐 */
      25. justify-content:space-around;
      26. /* 平均对齐 */
      27. justify-content: space-evenly;
      28. /* 交叉轴对齐 */
      29. /* 拉抻 */
      30. align-items: stretch;
      31. align-items:flex-start;
      32. align-items: flex-end;
      33. align-items:center;
      34. }
      35. .container > .item {
      36. padding: 1rem;
      37. /* height: 10rem; */
      38. background-color: lightcyan;
      39. border: 1px solid;
      40. }
      41. </style>
      42. </head>
      43. <body>
      44. <div class="container">
      45. <div class="item">item1</div>
      46. <div class="item">item2</div>
      47. <div class="item">item3</div>
      48. <div class="item">item4</div>
      49. </html>

  • flex属性
    flex 1 完全自适应

    • 效果图
      flex
    • 代码

      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. html {
      10. font-size: 10px;
      11. }
      12. body {
      13. font-size: 1.6rem;
      14. }
      15. /* flex容器 */
      16. .container {
      17. height: 20rem;
      18. border: 1px solid;
      19. display: flex;
      20. }
      21. /* flex项目 */
      22. .container > .item {
      23. /* max-width: 20rem; */
      24. width: 20rem;
      25. background-color: lightcyan;
      26. border: 1px solid;
      27. /* 项目的计算尺寸,优先级大于width,但小于min-width*/
      28. /* flex-basis: 项目在主轴的宽度; */
      29. /* flex-basis: 25rem; */
      30. /* 禁止收缩 */
      31. /* flex-shrink: 1; */
      32. /* 默认不允许放大 */
      33. /* flex-grow: 1; */
      34. /* flex:放大因子 收缩因子 计算大小 */
      35. /* flex默认:禁止放大,允许收缩,宽度自动 */
      36. /* flex: 0 1 auto; */
      37. /* 完全自适应 */
      38. /* flex:1 1 auto; */
      39. /* flex: auto; */
      40. /* 完全无弹性,用在pc端布局 */
      41. /* flex: 0 0 auto; */
      42. /* flex: none; */
      43. /* flex: 1;
      44. flex: 1 1 auto; */
      45. }
      46. .container > .item:first-of-type,
      47. .container > .item:last-of-type {
      48. background-color: lightgreen;
      49. flex: none;
      50. }
      51. .container > .item:first-of-type + .item {
      52. flex: 1;
      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. <!-- 三列布局,左右两列固定,中间自适应 -->
      62. </div>
      63. </body>
      64. </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