PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

博客列表 > flex布局-实践

flex布局-实践

︷肉園耔︷
︷肉園耔︷ 原创
2021年07月10日 23:43:30 529浏览

— flex 布局 属于弹性布局

  • flex 有主轴 和交叉轴和剩余空间的变换,可以随时可以让字元素以设置宽度来进行缩小和放大或者自适应
  • 图例:

-代码区

  1. *{
  2. box-sizing: border-box;
  3. margin: 0;
  4. padding: 0;
  5. }
  6. .container{
  7. display: flex;
  8. width: 40rem;
  9. height: 15em;
  10. border: 1px solid #000;
  11. /*主轴变横向*/
  12. /* flex-direction: column; */
  13. /*换行显示*/
  14. /* flex-flow: row wrap; */
  15. /*剩余空间位于所有项目的左边*/
  16. /* justify-content: flex-start;
  17. /*剩余空间位于所有项目的右边*/
  18. /*justify-content:flex-end;
  19. /*剩余空间位于所有项目的中边*/
  20. /* justify-content: center;
  21. /*剩余空间两端对齐*/
  22. /*justify-content: space-between;
  23. /*剩余空间分散对齐*/
  24. /*justify-content: space-around;
  25. /*剩余空间平均对齐*/
  26. /*justify-content: space-evenly;
  27. /*交叉轴对齐:交叉轴剩余空间*/
  28. /*align-items: stretch;*/
  29. /* align-items: flex-start; */
  30. /* align-items: flex-end; */
  31. /* align-items:center; */
  32. }
  33. .container > .itm{
  34. height: 10em;
  35. background-color: lightcyan;
  36. border: 1px solid #000;
  37. }
  38. .container {
  39. /* flex-direction: row nowrap; */
  40. /* flex-wrap: nowrap;*/
  41. /* flex-direction: row; */
  42. /* align-items:flex-start; */
  43. /*flex-direction:row-reverse;*/
  44. /* flex-direction:column-reverse; */
  45. }

— 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>Document</title>
    8. <style> .container{
    9. height:20rem;
    10. border: 1px solid;
    11. display: flex;
    12. }
    13. .container > .item {
    14. width: 20rem;
    15. background-color: lightcyan;
    16. border: 1px solid;
    17. /*项目的计算尺寸,优先级大于width */
    18. flex-basis: 25rem;
    19. /*禁止收缩*/
    20. /* flex-shrink: 1;
    21. /* 默认允许收缩 */
    22. /*flex-grow:1;
    23. flex-grow: 0; */
    24. /*flex默认:禁止放大,允许收缩,宽度自动*/
    25. /* flex: 0 1 auto; */
    26. /*flex 允许放大 允许缩小 宽度自动*/
    27. /*flex: 1 0 auto;*/
    28. /*单值语法*/
    29. /* flex: 1; */
    30. }
    31. .container > .item:first-of-type, .container > .item:last-of-type{
    32. background-color: lightgreen;
    33. flex: 0 1 auto;
    34. }
    35. .container > .item.two{
    36. background-color: violet;
    37. align-self: center;
    38. align-self:stretch;
    39. }
    40. </style>
    41. </head>
    42. <body>
    43. <div class="container">
    44. <div class="item">item1</div>
    45. <div class="item two">item2</div>
    46. <div class="item">item3</div>
    47. <!-- <div class="item">item4</div> -->
    48. </div>
    49. </body>
    50. </html>
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议