Blogger Information
Blog 27
fans 1
comment 2
visits 90522
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
隐式网格实例-对其方式以及间隙
          
Original
468 people have browsed it
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport"
  6. content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  7. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  8. <title>1027作业</title>
  9. <!-- 作业内容:
  10. 实例演示隐式网格, 对齐方式与行列间隙的设置方式与使用场景、前提-->
  11. </head>
  12. <style>
  13. /*对齐方式: 容器中: place-content, place-items
  14. 项目中: place-self*/
  15. /* 行列间隙 gap */
  16. /* gap: 垂直方向 水平方向 */
  17. /*1. 对齐前提: 必须存在"剩余空间"*/
  18. /*2. 对齐方案: "剩余空间"在"项目"之间的分配方式*/
  19. /*3. 剩余空间: Flex(主轴, 交叉轴), Grid(容器, 单元格)*/
  20. /*Grid: 剩余空间存在于"容器" 或 "单元格"*/
  21. /*容器中: place-content, place-items*/
  22. /*项目中: place-self*/
  23. /*容器*/
  24. .container{
  25. display: grid;
  26. border: 1px solid red;
  27. grid-template-rows:repeat(3,100px);
  28. grid-template-columns: repeat(3,100px);
  29. width: 500px;
  30. height: 400px;
  31. place-content: stretch;
  32. /*项目在单元格里面的对齐,垂直和水平都居中*/
  33. place-items: center;
  34. /*垂直间距10px 水平间距20px*/
  35. gap: 10px 20px;
  36. }
  37. /*显示网格*/
  38. .container .item{
  39. height: 50px;
  40. width: 50px;
  41. background-color: #f3d19e;
  42. }
  43. /*隐式网格*/
  44. .container .item.as{
  45. background-color: #55a532;
  46. }
  47. .container .item:nth-of-type(8){
  48. background-color: skyblue;
  49. /*item8 单元格内的对齐方式右边*/
  50. place-self:end ;
  51. }
  52. </style>
  53. <body>
  54. <div class="container">
  55. <div class="item">item-1</div>
  56. <div class="item">item-2</div>
  57. <div class="item">item-3</div>
  58. <div class="item">item-4</div>
  59. <div class="item">item-5</div>
  60. <div class="item">item-6</div>
  61. <div class="item">item-7</div>
  62. <div class="item">item-8</div>
  63. <div class="item">item-9</div>
  64. <!-- 增加三个,此是隐式网格-->
  65. <div class="item as">item-10</div>
  66. <div class="item as ">item-11</div>
  67. <div class="item as">item-12</div>
  68. </div>
  69. </body>
  70. </html>

运行结果

1.实例演示隐式网格


  1. 对齐方式:
  2. 容器中: place-content, place-items
  3. 项目中: place-self
  4. 对齐前提: 必须存在"剩余空间
  5. 对齐方案: "剩余空间"在"项目"之间的分配方式
  6. 容器中: place-content, place-items
  7. 项目中: place-self

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