Blogger Information
Blog 25
fans 0
comment 0
visits 13774
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
flex容器的常用属性及其使用案例
安超
Original
383 people have browsed it

1.html中flex容器的常用属性及其使用案例

flex容器的常用属性:
1.flex-direction: (row/column),默认是row
2.flex-wrap:是否换行 nowrap-不换行
3.justify-content:子元素沿主轴方向的的排列方式 flex-stat等
4.align-items:次轴方向是否缩放,如stretch
5.align-content:多上是否换行,如 start等
以上可以简化为:
1.flex-flow :flex-direction flex-wrap
2.place-content : justify-content
3.place-items :aligh-items align-content

  1. place-items
    常用的缩放代码:
    flex : flex-grow flex-shrank flex-basis

    2.flex容器的案例

    a.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>flex布局演示</title>
    8. </head>
    9. <body>
    10. <!-- flex中三个子元素居中显示 -->
    11. <div class="container">
    12. <div class="flex">1</div>
    13. <div class="flex">2</div>
    14. <div class="flex">3</div>
    15. </div>
    16. <style>
    17. .container{
    18. height: 15em;
    19. display: flex;
    20. background-color: aqua;
    21. flex-direction: row;
    22. justify-content: center;
    23. align-items: center;
    24. }
    25. .flex{
    26. border: 0.1em solid chocolate;
    27. text-align: center;
    28. width: 10em;
    29. height: 10em;
    30. background-color: brown;
    31. }
    32. </style>
    33. </body>
    34. </html>

    <!-- flex中的三个子元素,第一个第三个占25%,第二个占50% -->

  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. </head>
  9. <body>
  10. <!-- flex中三个子元素居中显示 -->
  11. <div class="container">
  12. <div class="flex">1</div>
  13. <div class="flex">2</div>
  14. <div class="flex">3</div>
  15. </div>
  16. <!-- flex中的三个子元素,第一个第三个占25%,第二个占50% -->
  17. <br>
  18. <div class="container_1">
  19. <div class="divchild">1</div>
  20. <div class="divchild">2</div>
  21. <div class="divchild">3</div>
  22. </div>
  23. <style>
  24. body{
  25. margin: 0;
  26. padding: 0;
  27. }
  28. .container_1{
  29. display: flex;
  30. width: 80%;
  31. h20em;
  32. background-color: chartreuse;
  33. justify-content: center;
  34. }
  35. .container_1 .divchild{
  36. border: 1px solid #000;
  37. text-align: center;
  38. height: 20em;
  39. }
  40. .container_1 .divchild:nth-of-type(1),
  41. .container_1 .divchild:nth-of-type(3)
  42. {
  43. flex:1;
  44. }
  45. .container_1 .divchild:nth-of-type(2){
  46. flex:3;
  47. }
  48. .container{
  49. height: 15em;
  50. display: flex;
  51. background-color: aqua;
  52. flex-direction: row;
  53. justify-content: center;
  54. align-items: center;
  55. }
  56. .flex{
  57. border: 0.1em solid chocolate;
  58. text-align: center;
  59. width: 10em;
  60. height: 10em;
  61. background-color: brown;
  62. }
  63. </style>
  64. </body>
  65. </html>
Correcting teacher:PHPzPHPz

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