博客列表 >Grid布局实现评论与回复(1228作业)

Grid布局实现评论与回复(1228作业)

暴风战斧
暴风战斧原创
2020年01月09日 21:58:04511浏览

手写的grid.md课件

Grid实现评论回复组件

思路与方案

对照评论回复组件效果图,最先想到的是可以划分为多行,然后分两列,把元素层级做一些调整,一层层对应到网格中去;
在实现的过程中,因为对flex方案印象最深刻,所以在写html的时候还是把元素层级划分太多了,写css时发现实在难以进行,于是赶紧把元素层级进行调整,基本写成同级了,这样再写css时特别舒服了,把元素一一放进网格中去,然后一个一个设置样式,及时查看效果进行调整!

本次作业总结

这次作业较flex布局是突破性的,因为最开始写的时候还是很受flex影响,差点不知道如何下手,看到效果图这么多元素差点以为我要画一个很密集的网格,后来复习了下课件,快速回顾了视频,再次整理下思路,最终一点点完成了效果。感觉自己掌握了flex和grid两大布局技术了,很开心!这一次在grid中其实混用了flex,最后的“发表时间”和“点赞回复”我是在grid中用的flex布局,两端对齐一步到位!从不会到跟着写,再到自己实现,感觉真的能学到东西,开心!

效果图

缩小

html代码
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>评论与回复Grid实现</title>
  6. <link rel="stylesheet" href="public_comment_reply.css">
  7. <link rel="stylesheet" href="../../1226/static/font/iconfont.css">
  8. <link rel="stylesheet" href="../../1226/componets/public/public_reset.css">
  9. </head>
  10. <body>
  11. <div class="container">
  12. <!--评论区-->
  13. <span>我要评论</span>
  14. <label for="comment">
  15. <img src="../../1226/static/images/user.png" alt="">
  16. </label>
  17. <textarea name="" id="comment" ></textarea>
  18. <button>发表评论</button>
  19. <!--回复区-->
  20. <span>最新回复</span>
  21. <span><img src="../../1226/static/images/user.png" alt=""></span>
  22. <div>
  23. <span>用户昵称</span>
  24. <span>留言内容:php中文网,是一个有温度,有思想的学习平台</span>
  25. <div>
  26. <span>2019-12-12 15:34:23发表</span>
  27. <span><i class="iconfont icon-dianzan"></i>回复</span>
  28. </div>
  29. </div>
  30. <span><img src="../../1226/static/images/user.png" alt=""></span>
  31. <div>
  32. <span>用户昵称</span>
  33. <span>留言内容:php中文网,是一个有温度,有思想的学习平台</span>
  34. <div>
  35. <span>2019-12-12 15:34:23发表</span>
  36. <span><i class="iconfont icon-dianzan"></i>回复</span>
  37. </div>
  38. </div>
  39. <span><img src="../../1226/static/images/user.png" alt=""></span>
  40. <div>
  41. <span>用户昵称</span>
  42. <span>留言内容:php中文网,是一个有温度,有思想的学习平台</span>
  43. <div>
  44. <span>2019-12-12 15:34:23发表</span>
  45. <span><i class="iconfont icon-dianzan"></i>回复</span>
  46. </div>
  47. </div>
  48. </div>
  49. </body>
  50. </html>
css代码
  1. /*评论与回复*/
  2. * {
  3. background-color: #fff;
  4. }
  5. img {
  6. width: 60px;
  7. border-radius: 5px;
  8. box-shadow: 0 0 5px #cccccc;
  9. }
  10. /** :not(body) {*/
  11. /*outline: 1px solid red;*/
  12. /*}*/
  13. .container {
  14. padding: 10px;
  15. width: auto;
  16. /*转为grid布局*/
  17. display: grid;
  18. grid-template-columns: 1fr 9fr;
  19. grid-template-rows: 60px 150px 60px 60px 1fr 1fr 1fr;
  20. grid-gap: 10px;
  21. grid-template-areas:
  22. 'a a'
  23. 'b1 b2'
  24. 'c c'
  25. 'd d'
  26. 'e1 e2'
  27. 'f1 f2'
  28. 'g1 g2';
  29. }
  30. /*评论区*/
  31. .container > span:nth-of-type(1) {
  32. grid-area: a;
  33. font-size: 14px;
  34. font-weight: bold;
  35. padding-top: 20px;
  36. border-top: 1px solid #cccccc;
  37. }
  38. .container > label {
  39. display: grid;
  40. align-self: start;
  41. }
  42. .container > label > img {
  43. display: grid;
  44. grid-area: b1;
  45. }
  46. .container > textarea {
  47. grid-area: b2;
  48. resize: none;
  49. border: 1px solid #cccccc;
  50. /*height: auto;*/
  51. /*min-width: 365px;*/
  52. /*max-width: 1200px;*/
  53. /*justify-content: space-between;*/
  54. }
  55. .container > textarea:hover {
  56. box-shadow: 0 0 5px #cccccc;
  57. }
  58. .container > button {
  59. grid-area: c;
  60. width: 150px;
  61. height: 40px;
  62. border: none;
  63. color: white;
  64. background-color: red;
  65. align-self: center;
  66. justify-self: end;
  67. }
  68. .container > button:hover {
  69. color: #ffffff;
  70. background-color: #178cee;
  71. cursor: pointer;
  72. box-shadow: 0 0 10px #cccccc;
  73. }
  74. .container > span:nth-of-type(2) {
  75. grid-area: d;
  76. font-size: 14px;
  77. font-weight: bold;
  78. padding-top: 20px;
  79. }
  80. /*回复内容*/
  81. .container > span:nth-of-type(3) {
  82. display: grid;
  83. align-self: center;
  84. }
  85. .container > span:nth-of-type(3) > img {
  86. display: grid;
  87. grid-area: e1;
  88. }
  89. .container > div:nth-of-type(1) {
  90. display: grid;
  91. grid-area: e2;
  92. height: 120px;
  93. align-items: center;
  94. }
  95. .container > div:nth-of-type(1) > div {
  96. display: flex;
  97. justify-content: space-between;
  98. }
  99. .container > span:nth-of-type(4) {
  100. display: grid;
  101. align-self: center;
  102. }
  103. .container > span:nth-of-type(4) > img {
  104. display: grid;
  105. grid-area: f1;
  106. }
  107. .container > div:nth-of-type(2) {
  108. display: grid;
  109. grid-area: f2;
  110. align-items: center;
  111. }
  112. .container > div:nth-of-type(2) > div {
  113. display: flex;
  114. justify-content: space-between;
  115. }
  116. .container > span:nth-of-type(5) {
  117. display: grid;
  118. align-self: center;
  119. }
  120. .container > span:nth-of-type(5) > img {
  121. display: grid;
  122. grid-area: g1;
  123. }
  124. .container > div:nth-of-type(3) {
  125. display: grid;
  126. grid-area: g2;
  127. align-items: center;
  128. }
  129. .container > div:nth-of-type(3) > div {
  130. display: flex;
  131. justify-content: space-between;
  132. }
  133. .container i {
  134. font-size: 23px;
  135. color: red;
  136. margin-right: 4px;
  137. }
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议