Blogger Information
Blog 16
fans 0
comment 0
visits 15840
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1222 flex容器的常用属性 与布局展示
Allen在php中文网的学习笔记
Original
641 people have browsed it

作业

作业内容:将flex容器与项目的常用属性全部进行实例演示,并理解属性的常用值的显示效果
演示地址: https://php.gzj2001.com/1221/index.html
image.png

作业代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>1222作业</title>
  7. <style>
  8. /* 初始化一些默认参数 并使用IE盒子 */
  9. * {
  10. padding: 0;
  11. margin: 0;
  12. box-sizing: border-box;
  13. }
  14. /* 将容器转换为flex弹性容器 */
  15. .container {
  16. /* 转换flex容器 */
  17. display: flex;
  18. /* 添加边框便于观察 */
  19. border: 1px solid red;
  20. /* 设置高度 */
  21. height: 20em;
  22. /* 设置内边距 */
  23. padding: 1em;
  24. /* 设置外边距 */
  25. margin: 1em;
  26. /* 弹性容器主要属性 */
  27. /* 主轴方向与是否换行 */
  28. flex-flow: row wrap;
  29. /* 一行项目在主轴上的位置 */
  30. /* justify-content:center; */
  31. /* 一行项目在交叉轴上的位置 */
  32. /* align-items: center; */
  33. }
  34. .container>.item {
  35. /* 给项目添加背景色便于观察 */
  36. background-color: lightyellow;
  37. /* 给项目添加边框便于观察 */
  38. border: 1px solid springgreen;
  39. /* 设置宽度便于观察 */
  40. width: 5em;
  41. }
  42. /* 项目常用属性 flex展示 【设置基本项目的伸缩与宽度】 */
  43. .container .item {
  44. /* 默认 */
  45. flex: initial;
  46. /* 允许放大 和 缩放 */
  47. flex: auto;
  48. /* 禁止放大和 缩放 */
  49. flex: none;
  50. }
  51. /* 项目常用属性 align-self展示 【某个项目的对齐方式 】 */
  52. /* 以第八个项目为例来展示 */
  53. .container .item:nth-of-type(8) {
  54. /* 默认伸展 */
  55. align-self: stretch;
  56. /* 从上往下 */
  57. /* align-self: flex-start; */
  58. /* 从下往上 */
  59. /* align-self: flex-end; */
  60. /* 居中 */
  61. /* align-self: center; */
  62. }
  63. /* 项目常用属性 order展示 【置某个项目在主轴上的排列顺序】*/
  64. .container .item:nth-of-type(1) {
  65. background-color: green;
  66. order: 2;
  67. }
  68. .container .item:nth-of-type(2) {
  69. background-color: #000;
  70. order: 5;
  71. }
  72. .container .item:nth-of-type(3) {
  73. background-color: #fff;
  74. order: 1;
  75. }
  76. .container .item:nth-of-type(4) {
  77. background-color: #456789;
  78. order: 4;
  79. }
  80. .container .item:nth-of-type(5) {
  81. background-color: #987654;
  82. order: 8;
  83. }
  84. .container .item:nth-of-type(6) {
  85. background-color: #red
  86. order: -1;
  87. }
  88. .container .item:nth-of-type(7) {
  89. background-color: #658963;
  90. order: 6;
  91. }
  92. </style>
  93. </head>
  94. <body>
  95. <div class="container">
  96. <div class="item">1</div>
  97. <div class="item">2</div>
  98. <div class="item">3</div>
  99. <div class="item">4</div>
  100. <div class="item">5</div>
  101. <div class="item">6</div>
  102. <div class="item">7</div>
  103. <div class="item">8</div>
  104. </div>
  105. </body>
  106. </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