Blogger Information
Blog 32
fans 2
comment 2
visits 23239
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Grid容器/项目属性练习(1230作业)
暴风战斧
Original
970 people have browsed it

Grid容器/项目属性演示

思路方案

在演示之前已经实战了grid布局了,本次将grid容器和项目属性复习一一演示;
本次复习作业,没有单独写css,直接在html中用<style></style>写样式,将属性分类进行效果演示!

作业总结

经过上一次作业grid布局实战和本次再次加强属性印象,现在对grid布局更加深刻了,感觉grid还是比flex要高效一些!

效果图

划分行、列及间距
grid-template-colums
grid-template-rows
grid-column-gap | grid-row-gap | grid-gap | gap

命名网格区域
grid-auto-flow
grid-template-area

隐式行高/列宽
grid-auto-columns

grid-auto-rows

对齐方式
align-content/justify-content
align-items/justify-content
align-self/justify-self

将指定项目放入指定单元格
grid-column-start/end
grid-row-start/end
grid-area

html代码
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>grid容器项目属性</title>
  6. <link rel="stylesheet" href="../1226/componets/public/public_reset.css">
  7. <style>
  8. /*网格属性演示*/
  9. .container {
  10. display: grid;
  11. background-color: #fff;
  12. padding: 10px;
  13. margin: 10px auto;
  14. width: 500px;
  15. height: 300px;
  16. /*划分行和列及间距*/
  17. grid-template-columns: repeat(2,250px);
  18. grid-template-rows: repeat(2,150px);
  19. grid-gap: 10px;
  20. /*命名网格区域*/
  21. grid-template-areas: 'a b' 'c d';
  22. /*隐式网格列宽与行高*/
  23. /*grid-auto-rows: 20px;*/
  24. /*grid-auto-flow: column;*/
  25. /*grid-auto-columns: 60px;*/
  26. /*项目对齐方式*/
  27. /*justify-content: center;*/
  28. /*align-content: center;*/
  29. place-content: center
  30. }
  31. .container > .item {
  32. display: grid;
  33. background-color: lightgoldenrodyellow;
  34. /*项目对齐方式*/
  35. /*justify-items: center;*/
  36. /*align-items: center;*/
  37. place-items: center
  38. }
  39. .container > .item {
  40. font-size: 60px;
  41. }
  42. .container > .item:nth-of-type(3) {
  43. /*把项目3放进单元格b中*/
  44. /*grid-column-start: 2;*/
  45. /*grid-column-end: 3;*/
  46. /*grid-row-start: 1;*/
  47. /*grid-row-end: 2;*/
  48. grid-area: b;
  49. background-color: lightgreen;
  50. }
  51. .container > .item:nth-of-type(2) {
  52. /*设置特定特定项目对齐*/
  53. background-color: lightpink;
  54. /*justify-self: start;*/
  55. /*align-self: start;*/
  56. place-self: start;
  57. }
  58. </style>
  59. </head>
  60. <body>
  61. <div class="container">
  62. <div class="item">1</div>
  63. <div class="item">2</div>
  64. <div class="item">3</div>
  65. <div class="item">4</div>
  66. <!--<div class="item">5</div>-->
  67. <!--<div class="item">6</div>-->
  68. </div>
  69. </body>
  70. </html>
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:现在已学到php了, 前端的作业可以抽空写, 跟上来
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