Blogger Information
Blog 11
fans 0
comment 1
visits 7822
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
flex元素常用属性
一代宗师
Original
601 people have browsed it

弹性容器与弹性项目

1.任何元素都可以通过display:flex属性来转换为弹性盒子元素
2.使用display:flex属性的元素叫flex容器
3.flex容器中的元素叫做flex项目
4.flex容器中的flex项目都会变成行内块元素
5.转变为flex元素后,它内部子元素就支持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>弹性容器与弹性项目</title>
  8. <style>
  9. *{box-sizing: border-box;}
  10. .main{
  11. display: flex;
  12. border: 1px solid;
  13. height: 20em;
  14. }
  15. .main>.imt{
  16. border: 1px solid;
  17. width: 10em;
  18. height: 8em;
  19. }
  20. </style>
  21. </head>
  22. <body>
  23. <div class="main">
  24. <div class="imt">imt1</div>
  25. <div class="imt">imt2</div>
  26. <div class="imt">imt3</div>
  27. </div>
  28. </body>
  29. </html>

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. *{
  10. box-sizing: border-box;
  11. }
  12. .main{
  13. display: flex;
  14. height: 15em;
  15. border: 1px solid;
  16. }
  17. /* 单行排列 */
  18. .text{
  19. width: 5em;
  20. border: 1px solid;
  21. }
  22. .main{
  23. flex-flow: row nowrap;
  24. }
  25. /* 多行排列 */
  26. .text{
  27. width: 5em;
  28. height: 5em;
  29. border: 1px solid;
  30. }
  31. .main{
  32. flex-flow: row wrap;
  33. }
  34. /* 主轴为列 */
  35. .text{
  36. width: 5em;
  37. height: 5em;
  38. border: 1px solid;
  39. }
  40. .main{
  41. flex-flow: column nowrap;
  42. }
  43. /*列换行 */
  44. .text{
  45. width: 5em;
  46. height: 5em;
  47. border: 1px solid;
  48. }
  49. .main{
  50. flex-flow: column wrap;
  51. }
  52. </style>
  53. </head>
  54. <body>
  55. <div class="main">
  56. <div class="text">text1</div>
  57. <div class="text">text2</div>
  58. <div class="text">text3</div>
  59. <div class="text">text4</div>
  60. <div class="text">text5</div>
  61. <div class="text">text6</div>
  62. <div class="text">text7</div>
  63. <div class="text">text8</div>
  64. </div>
  65. </body>
  66. </html>

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

  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. *{box-sizing: border-box;}
  10. .main{
  11. display: flex;
  12. height: 10em;
  13. border: 1px solid;
  14. }
  15. .text{
  16. width: 4em;
  17. /* height: 2em; */
  18. border: 1px solid;
  19. }
  20. /* 设置在单行容器上对齐前提:主轴上存在剩余空间 */
  21. /* 空间分配有两种 */
  22. /* 1.将所有项目视为一体,在项目两边进行分配 */
  23. .main{
  24. justify-content: center;
  25. justify-content: flex-start;
  26. justify-content: flex-end;
  27. }
  28. /* 2.将项目分为一个个独立的个体,在项目之间分配 */
  29. .main{
  30. /* 分散对齐 */
  31. justify-content: space-around;
  32. /* 两端对齐 */
  33. justify-content: space-between;
  34. /* 平均对齐 */
  35. justify-content: space-evenly;
  36. }
  37. /* 交叉轴对齐方式 */
  38. .main{
  39. /* 默认拉伸 */
  40. align-items: stretch;
  41. /* 顶部对齐 */
  42. align-items: flex-start;
  43. /* 底部对齐 */
  44. align-items: flex-end;
  45. /* 居中 */
  46. align-items: center;
  47. }
  48. /* 注意:单行容器切项目在主轴排列,交叉轴不存在适应空间.原因是单行容器,在交叉轴上只有一行没有多行 */
  49. </style>
  50. </head>
  51. <body>
  52. <div class="main">
  53. <div class="text">text1</div>
  54. <div class="text">text2</div>
  55. <div class="text">text3</div>
  56. <div class="text">text4</div>
  57. </div>
  58. </body>
  59. </html>

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. *{box-sizing: border-box;}
  10. .main{
  11. display: flex;
  12. height: 10em;
  13. border: 1px solid;
  14. }
  15. .text{
  16. width: 4em;
  17. height: 2em;
  18. border: 1px solid;
  19. }
  20. /* 设置在单行容器上对齐前提:主轴上存在剩余空间 */
  21. /* 空间分配有两种 */
  22. /* 1.将所有项目视为一体,在项目两边进行分配 */
  23. .main{
  24. flex-flow: row wrap;
  25. }
  26. .main{
  27. align-content: center;
  28. align-content: flex-start;
  29. align-content: flex-end;
  30. align-content: space-around;
  31. align-content: space-between;
  32. align-content: space-evenly;
  33. }
  34. </style>
  35. </head>
  36. <body>
  37. <div class="main">
  38. <div class="text">text1</div>
  39. <div class="text">text2</div>
  40. <div class="text">text3</div>
  41. <div class="text">text4</div>
  42. <div class="text">text5</div>
  43. <div class="text">text6</div>
  44. <div class="text">text7</div>
  45. <div class="text">text8</div>
  46. <div class="text">text9</div>
  47. <div class="text">text10</div>
  48. <div class="text">text11</div>
  49. <div class="text">text12</div>
  50. <div class="text">text1</div>
  51. <div class="text">text2</div>
  52. <div class="text">text3</div>
  53. <div class="text">text4</div>
  54. <div class="text">text5</div>
  55. <div class="text">text6</div>
  56. <div class="text">text7</div>
  57. <div class="text">text8</div>
  58. <div class="text">text9</div>
  59. <div class="text">text10</div>
  60. <div class="text">text11</div>
  61. <div class="text">text12</div>
  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