Blogger Information
Blog 13
fans 0
comment 0
visits 8355
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1222 将flex容器与项目的常用属性全部进行实例演示,并理解属性的常用值的显示效果
一米互联
Original
659 people have browsed it

将flex容器与项目的常用属性全部进行实例演示,并理解属性的常用值的显示效果

运用flex容器布局

  1. <style>
  2. *{
  3. margin: 0;
  4. padding: 0;
  5. box-sizing: border-box;
  6. }
  7. body *:not(.content) {
  8. background: rgb(4, 207, 180);
  9. }
  10. header,footer{
  11. height: 5vh;
  12. }
  13. .content{
  14. display: flex;
  15. height: 90vh;
  16. }
  17. .content aside{
  18. min-width: 15em;
  19. }
  20. .content main {
  21. min-width: calc(100% - 30em);
  22. margin: 0 0.5em;
  23. }
  24. .content{
  25. margin: 0.5em 0;
  26. height: calc(90vh - 1em);
  27. }
  28. .content main {
  29. min-width: calc(100% - 30em - 1em);
  30. }
  31. </style>
  32. </head>
  33. <body>
  34. <header>头部</header>
  35. <div class="content">
  36. <aside>左侧内容</aside>
  37. <main>主体内容</main>
  38. <aside>右侧内容</aside>
  39. </div>
  40. <footer>尾部</footer>
  41. </body>

项目的常用属性

1.运用display: flex;的元素被称为flex容器,它的所有子元素称为flex项目。并且容器中的项目自动转为”行内块元素”。

flex-flow属性:
  1. <style>
  2. *{
  3. margin: 0;
  4. padding: 0;
  5. box-sizing: border-box;
  6. }
  7. .content{
  8. display: flex;
  9. height: 15em;
  10. border: 1px solid black;
  11. padding: 1em;
  12. margin: 1em;
  13. }
  14. .content>.one{
  15. width: 5em;
  16. height: 5em;
  17. background:rgb(198, 231, 7);
  18. border: 1px solid blue;
  19. }
  20. .content{
  21. flex-flow: row nowrap;
  22. /*单行容器,主轴为水平方向 不换行*/
  23. }
  24. .content{
  25. flex-flow:column nowrap;
  26. /*单行容器,主轴为垂直方向 不换行*/
  27. }
  28. .content{
  29. flex-flow:column wrap;
  30. /*单行容器,主轴为垂直方向 可换行*/
  31. }
  32. </style>
  33. </head>
  34. <body>
  35. <div class="content">
  36. <div class="one">内容1</div>
  37. <div class="one">内容2</div>
  38. <div class="one">内容3</div>
  39. <div class="one">内容4</div>
  40. <div class="one">内容5</div>
  41. <div class="one">内容6</div>
  42. <div class="one">内容7</div>
  43. <div class="one">内容8</div>
  44. </div>



justify-content属性:
  1. .content{
  2. justify-content: flex-start;
  3. /*默认左对齐*/
  4. justify-content: flex-end;
  5. /*右对齐*/
  6. justify-content: center;
  7. /*居中对齐*/
  8. }
  9. .content{
  10. align-items: stretch;
  11. /* 默认交叉轴(垂直方向)对齐方式 */
  12. align-items: flex-start;
  13. /* 上 */
  14. align-items: flex-end;
  15. /* 下 */
  16. align-items: center;
  17. /* 中间 */
  18. }







align-content属性:
  1. .content{
  2. flex-flow: row wrap;
  3. /*项目在多行容器中的交叉轴上的对齐方式 */
  4. align-content: stretch;
  5. align-content: flex-start;
  6. align-content: flex-end;
  7. align-content: center;
  8. align-content: space-between;
  9. align-content: space-around;
  10. align-content: space-evenly;
  11. }






flex: 放大因子 收缩因子 项目在主轴上的基准宽度

  1. .content .one {
  2. /* 允许放大和收缩 */
  3. flex: 1 1 auto;
  4. flex: auto;
  5. }


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