博主信息
博文 43
粉丝 0
评论 0
访问量 39461
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
flex容器
橙絮圆
原创
651人浏览过

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>
批改老师:天蓬老师天蓬老师

批改状态:合格

老师批语:很直观
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学