博客列表 >2019年12月28日 作业 grid布局了解+布局实现

2019年12月28日 作业 grid布局了解+布局实现

L
L原创
2019年12月30日 14:52:57572浏览

网格布局了解 grid

术语

网格线 grid lines:编号,命名

轨道 grid tracks:两条网格线间的区域,fr,%,px,auto-fill

单元格 grid cell:四条网格线包起来的区域

网格区域 grid area:多个单元格形成的区域

网格间距 grid gap:行或列之间的间隙

容器属性

grid-template-columns:定义网格列大小,

如:grid-template-columns: 1fr 1fr;

grid-template-rows 定义网格行大小

如:grid-template-rows: 300px 300px;

grid-template-areas 网格命名

“.”占位作用

grid-gap 网格间隙

grid-column-gap 列间隙

grid-row-gap 行间隙

grid-gap 行列间隙合并写,顺序先行后列

元素属性

grid-row-start/end grid-cloumn-start/end 将元素放入网格起止线之间的单元格

简写 grid-row: 起/止; grid-column: 起/止; 再简写 grid-area: 行起/列起/行止/列止;


grid布局实现

二手商品交易

效果图

html代码

  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. <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  7. <link rel="stylesheet" href="grid_test.css" />
  8. <title>二手商品交易</title>
  9. </head>
  10. <body>
  11. <div class="public_headline">
  12. <span>二手交易</span>
  13. </div>
  14. <!-- 二手交易区 -->
  15. <div class="public_second_hand">
  16. <!-- 标题1 -->
  17. <div class="title1">
  18. <a href="">抢好货</a>
  19. <span>0低价, 便捷,安全,快速</span>
  20. </div>
  21. <!-- 标题2 -->
  22. <div class="title2">
  23. <span>热门分类</span>
  24. <a href="">分类1</a>
  25. <a href="">分类2</a>
  26. <a href="">分类3</a>
  27. <a href="">分类4</a>
  28. <a href="">分类5</a>
  29. </div>
  30. <!-- 商品展示区 -->
  31. <div class="goods">
  32. <!-- 左侧商品列表 -->
  33. <div class="goods-list">
  34. <!-- 商品简介 -->
  35. <div class="intro">
  36. <a href="">
  37. <img src="static/images/shop/shop3.jpg" alt="" width="176" height="120" />
  38. </a>
  39. <a href="">美女性感写真海报墙艺术装饰画贴画图</a>
  40. <div>
  41. <span>&yen; 888</span>
  42. <span>美女</span>
  43. </div>
  44. </div>
  45. <div class="intro">
  46. <a href=""><img src="static/images/shop/shop2.jpg" alt="" width="176" height="120" /></a>
  47. <a href="">美女性感写真海报墙艺术装饰画贴画图</a>
  48. <div>
  49. <span>&yen; 888</span>
  50. <span>美女</span>
  51. </div>
  52. </div>
  53. <div class="intro">
  54. <a href=""><img src="static/images/shop/shop3.jpg" alt="" width="176" height="120" /></a>
  55. <a href="">美女性感写真海报墙艺术装饰画贴画图</a>
  56. <div>
  57. <span>&yen; 888</span>
  58. <span>美女</span>
  59. </div>
  60. </div>
  61. <div class="intro">
  62. <a href=""><img src="static/images/shop/shop6.jpg" alt="" width="176" height="120" /></a>
  63. <a href="">美女性感写真海报墙艺术装饰画贴画图</a>
  64. <div>
  65. <span>&yen; 888</span>
  66. <span>美女</span>
  67. </div>
  68. </div>
  69. <div class="intro">
  70. <a href=""><img src="static/images/shop/shop3.jpg" alt="" width="176" height="120" /></a>
  71. <a href="">美女性感写真海报墙艺术装饰画贴画图</a>
  72. <div>
  73. <span>&yen; 888</span>
  74. <span>美女</span>
  75. </div>
  76. </div>
  77. <div class="intro">
  78. <a href=""><img src="static/images/shop/shop8.jpg" alt="" width="176" height="120" /></a>
  79. <a href="">美女性感写真海报墙艺术装饰画贴画图</a>
  80. <div>
  81. <span>&yen; 888</span>
  82. <span>美女</span>
  83. </div>
  84. </div>
  85. <div class="intro">
  86. <a href=""><img src="static/images/shop/shop6.jpg" alt="" width="176" height="120" /></a>
  87. <a href="">美女性感写真海报墙艺术装饰画贴画图</a>
  88. <div>
  89. <span>&yen; 888</span>
  90. <span>美女</span>
  91. </div>
  92. </div>
  93. <div class="intro">
  94. <a href=""><img src="static/images/shop/shop7.jpg" alt="" width="176" height="120" /></a>
  95. <a href="">美女性感写真海报墙艺术装饰画贴画图</a>
  96. <div>
  97. <span>&yen; 888</span>
  98. <span>美女</span>
  99. </div>
  100. </div>
  101. </div>
  102. <!-- 右侧快速入口 -->
  103. <div class="quick-entry">
  104. <div class="quick-1">
  105. <a href=""><img src="static/images/ad/1.png" alt="" /></a>
  106. <a href=""><img src="static/images/ad/2.png" alt="" /></a>
  107. <a href=""><img src="static/images/ad/3.png" alt="" /></a>
  108. <a href=""><img src="static/images/ad/4.png" alt="" /></a>
  109. </div>
  110. <div class="quick-2">
  111. <a href=""><img src="static/images/ad/image.png" alt="" /></a>
  112. <a href=""><img src="static/images/ad/ad2.jpg" alt="" /></a>
  113. </div>
  114. </div>
  115. </div>
  116. </div>
  117. </body>
  118. </html>

css样式

  1. /* 导入公共初始化样式 */
  2. @import "public_reset.css";
  3. .public_headline {
  4. padding: 20px;
  5. text-align: center;
  6. }
  7. .public_headline span {
  8. font-size: 24px;
  9. font-weight: bold;
  10. margin-bottom: 10px;
  11. border-bottom: 4px solid red;
  12. }
  13. /* 商品 */
  14. .public_second_hand {
  15. width: 1200px;
  16. padding: 10px;
  17. box-sizing: border-box;
  18. margin: auto;
  19. border: 1px solid #cccccc;
  20. border-radius: 5px;
  21. }
  22. .public_second_hand:hover {
  23. box-shadow: 0 0 10px #cccccc;
  24. }
  25. .public_second_hand > .title1 {
  26. height: 50px;
  27. border-bottom: 1px solid #cccccc;
  28. }
  29. /* 标题1 */
  30. .public_second_hand > .title1 > a {
  31. font-size: 24px;
  32. margin-right: 15px;
  33. }
  34. .public_second_hand > .title1 > span {
  35. color: red;
  36. }
  37. /* 标题2 */
  38. .public_second_hand > .title2 {
  39. height: 50px;
  40. }
  41. .public_second_hand > .title2 > span {
  42. font-size: 24px;
  43. color: red;
  44. }
  45. .public_second_hand > .title2 > a {
  46. padding-left: 15px;
  47. }
  48. /* 商品列表 */
  49. .public_second_hand > .goods {
  50. display: grid;
  51. grid-template-columns: 2fr 1fr;
  52. grid-template-rows: auto;
  53. grid-gap: 10px;
  54. }
  55. .public_second_hand > .goods > .goods-list {
  56. display: grid;
  57. grid-template-columns: repeat(4, 1fr);
  58. grid-template-rows: repeat(2, 1fr);
  59. grid-gap: 10px;
  60. }
  61. .public_second_hand > .goods > .quick-entry {
  62. display: grid;
  63. grid-template-columns: 1fr;
  64. grid-template-rows: 2fr 1fr;
  65. grid-gap: 10px;
  66. }
  67. .public_second_hand > .goods > .quick-entry > .quick-1 {
  68. display: grid;
  69. grid-template-columns: repeat(2, 1fr);
  70. grid-template-rows: repeat(2, 1fr);
  71. grid-gap: 10px;
  72. }
  73. .public_second_hand > .goods > .goods-list > .intro {
  74. display: flex;
  75. flex-flow: column nowrap;
  76. justify-content: space-between;
  77. }
  78. .public_second_hand > .goods > .goods-list > .intro img {
  79. border: 1px solid #cccccc;
  80. border-radius: 5px;
  81. }
  82. .public_second_hand > .goods > .goods-list > .intro > div {
  83. display: flex;
  84. }
  85. .public_second_hand > .goods > .goods-list > .intro > div > span:first-child {
  86. color: red;
  87. }
  88. .public_second_hand > .goods > .goods-list > .intro > div > span:last-child {
  89. color: #ffffff;
  90. background-color: #55ce9f;
  91. padding: 0 5px;
  92. margin-left: auto;
  93. }
  94. .public_second_hand > .goods > .quick-entry > .quick-2 {
  95. display: flex;
  96. flex-flow: column nowrap;
  97. justify-content: space-between;
  98. }
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议