博客列表 >2019年12月26日 作业 flex弹性盒子实战:“二手商品交易”+“评论与回复”

2019年12月26日 作业 flex弹性盒子实战:“二手商品交易”+“评论与回复”

L
L原创
2019年12月28日 18:07:58936浏览

作业是根据老师上课布局思路,自行构建写的,重新提交,希望得到老师对作业的肯定

实战思路

先分析效果图,通过flex布局特点(主轴方向,子元素是否换行,子元素扩展与收缩,排列对齐方式等),逐步构建html代码结构,进而通过css中flex实现效果

1.二手商品交易

效果


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="public_second_hand.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>¥ 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>¥ 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>¥ 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>¥ 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>¥ 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>¥ 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>¥ 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>¥ 888</span>
  98. <span>美女</span>
  99. </div>
  100. </div>
  101. </div>
  102. <!-- 右侧快速入口 -->
  103. <div class="quick-entry">
  104. <a href=""><img src="../../static/images/ad/1.png" alt="" /></a>
  105. <a href=""><img src="../../static/images/ad/2.png" alt="" /></a>
  106. <a href=""><img src="../../static/images/ad/3.png" alt="" /></a>
  107. <a href=""><img src="../../static/images/ad/4.png" alt="" /></a>
  108. <div>
  109. <a href=""><img src="../../static/images/ad/image.png" alt="" /></a>
  110. <a href=""><img src="../../static/images/ad/ad2.jpg" alt="" /></a>
  111. </div>
  112. </div>
  113. </div>
  114. </div>
  115. </body>
  116. </html>

css样式

public_second_hand.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. height: 440px;
  51. display: flex;
  52. }
  53. .public_second_hand > .goods > .goods-list {
  54. padding: 10px;
  55. flex-basis: 800px;
  56. display: flex;
  57. flex-flow: row wrap;
  58. justify-content: space-between;
  59. }
  60. .public_second_hand > .goods > .goods-list > .intro {
  61. width: 178px;
  62. height: 200px;
  63. display: flex;
  64. flex-flow: column nowrap;
  65. justify-content: space-between;
  66. }
  67. .public_second_hand > .goods > .goods-list > .intro img {
  68. border: 1px solid #cccccc;
  69. border-radius: 5px;
  70. }
  71. .public_second_hand > .goods > .goods-list > .intro > div {
  72. display: flex;
  73. }
  74. .public_second_hand > .goods > .goods-list > .intro > div > span:first-child {
  75. color: red;
  76. }
  77. .public_second_hand > .goods > .goods-list > .intro > div > span:last-child {
  78. color: #ffffff;
  79. background-color: #55ce9f;
  80. padding: 0 5px;
  81. margin-left: auto;
  82. }
  83. .public_second_hand > .goods > .quick-entry {
  84. padding: 10px;
  85. flex-basis: 400px;
  86. display: flex;
  87. flex-flow: row wrap;
  88. justify-content: space-between;
  89. }
  90. .public_second_hand > .goods > .quick-entry img {
  91. width: 190px;
  92. height: 130px;
  93. }
  94. .public_second_hand > .goods > .quick-entry > div {
  95. width: 400px;
  96. display: flex;
  97. flex-direction: column;
  98. }
  99. .public_second_hand > .goods > .quick-entry > div img {
  100. width: 393px;
  101. height: 60px;
  102. }

公共初始化样式public_reset.css

  1. * {
  2. margin: 0;
  3. padding: 0;
  4. }
  5. body {
  6. color: #333;
  7. background-color: #ffffff;
  8. }
  9. a {
  10. color: #333;
  11. text-decoration: none;
  12. }
  13. li {
  14. list-style: none;
  15. }

2.评论回复

效果


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="../../static/font/iconfont.css" />
  8. <link rel="stylesheet" href="public-comment-reply.css" />
  9. <title>评论回复</title>
  10. </head>
  11. <body>
  12. <div class="public-comment-reply">
  13. <!-- 评论 -->
  14. <div class="comment">
  15. <h3>我要评论</h3>
  16. <div>
  17. <label for="comment">
  18. <img src="../../static/images/user.png" alt="" />
  19. </label>
  20. <textarea name="comment" id="comment"></textarea>
  21. </div>
  22. <button>发表评论</button>
  23. </div>
  24. <!-- 回复 -->
  25. <div class="reply">
  26. <h3>最新回复</h3>
  27. <div>
  28. <img src="../../static/images/user.png" alt="" />
  29. <div>
  30. <span>用户昵称</span>
  31. <span>留言内容: Run Albania hacking</span>
  32. <div>
  33. <span>2019-12-12 15:34:23发表</span>
  34. <span>
  35. <i class="icon iconfont icon-dianzan"></i>
  36. 回复
  37. </span>
  38. </div>
  39. </div>
  40. </div>
  41. <div>
  42. <img src="../../static/images/user.png" alt="" />
  43. <div>
  44. <span>用户昵称</span>
  45. <span>留言内容: Run Albania hacking</span>
  46. <div>
  47. <span>2019-12-12 15:34:23发表</span>
  48. <span>
  49. <i class="icon iconfont icon-dianzan"></i>
  50. 回复
  51. </span>
  52. </div>
  53. </div>
  54. </div>
  55. <div>
  56. <img src="../../static/images/user.png" alt="" />
  57. <div>
  58. <span>用户昵称</span>
  59. <span>留言内容: Run Albania hacking</span>
  60. <div>
  61. <span>2019-12-12 15:34:23发表</span>
  62. <span>
  63. <i class="icon iconfont icon-dianzan"></i>
  64. 回复
  65. </span>
  66. </div>
  67. </div>
  68. </div>
  69. <div>
  70. <img src="../../static/images/user.png" alt="" />
  71. <div>
  72. <span>用户昵称</span>
  73. <span>留言内容: Run Albania hacking</span>
  74. <div>
  75. <span>2019-12-12 15:34:23发表</span>
  76. <span>
  77. <i class="icon iconfont icon-dianzan"></i>
  78. 回复
  79. </span>
  80. </div>
  81. </div>
  82. </div>
  83. <div>
  84. <img src="../../static/images/user.png" alt="" />
  85. <div>
  86. <span>用户昵称</span>
  87. <span>留言内容: Run Albania hacking</span>
  88. <div>
  89. <span>2019-12-12 15:34:23发表</span>
  90. <span>
  91. <i class="icon iconfont icon-dianzan"></i>
  92. 回复
  93. </span>
  94. </div>
  95. </div>
  96. </div>
  97. </div>
  98. </div>
  99. </body>
  100. </html>

css样式public-comment-reply.css

  1. /* 导入公共初始化样式 */
  2. @import "../public_reset.css";
  3. .public-comment-reply {
  4. padding: 20px;
  5. box-sizing: border-box;
  6. display: flex;
  7. flex-direction: column;
  8. }
  9. /* 评论 */
  10. .public-comment-reply > .comment {
  11. display: flex;
  12. flex-direction: column;
  13. }
  14. .public-comment-reply > .comment h3 {
  15. border-top: 1px solid #cccccc;
  16. padding-top: 20px;
  17. }
  18. .public-comment-reply > .comment > div {
  19. height: 200px;
  20. padding: 15px;
  21. display: flex;
  22. }
  23. .public-comment-reply > .comment > div img {
  24. width: 60px;
  25. height: 60px;
  26. }
  27. .public-comment-reply > .comment > div textarea {
  28. height: 200px;
  29. margin-left: 20px;
  30. padding: 10px;
  31. box-sizing: border-box;
  32. flex: auto;
  33. }
  34. .public-comment-reply > .comment > div textarea:hover {
  35. box-shadow: 0 0 8px #cccccc;
  36. }
  37. .public-comment-reply > .comment > button {
  38. width: 120px;
  39. height: 40px;
  40. align-self: flex-end;
  41. margin-right: 15px;
  42. border: none;
  43. background-color: #f64c59;
  44. color: #ffffff;
  45. cursor: pointer;
  46. }
  47. .public-comment-reply > .comment > button:hover {
  48. background-color: #178cee;
  49. box-shadow: 0 0 8px #cccccc;
  50. }
  51. .public-comment-reply > .reply {
  52. display: flex;
  53. flex-direction: column;
  54. }
  55. .public-comment-reply > .reply h3 {
  56. padding: 20px 0;
  57. }
  58. .public-comment-reply > .reply > div {
  59. display: flex;
  60. }
  61. .public-comment-reply > .reply > div > img {
  62. width: 60px;
  63. height: 60px;
  64. align-self: center;
  65. }
  66. .public-comment-reply > .reply > div > div {
  67. height: 100px;
  68. margin-left: 20px;
  69. flex: auto;
  70. display: flex;
  71. flex-direction: column;
  72. justify-content: space-between;
  73. }
  74. .public-comment-reply > .reply > div > div > div {
  75. display: flex;
  76. justify-content: space-between;
  77. }
  78. .public-comment-reply > .reply > div > div > div i {
  79. color: red;
  80. font-size: 1.2rem;
  81. margin-right: 5px;
  82. }
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议
李**¹⁸⁰³⁹⁵⁴⁰¹²⁰2019-12-28 15:01:012楼
如果实在介意,你可以重新编辑一下作业,在提交,作业就会变成为批改状态,咱们的作业提交时间不一样,有的人晚,有的早,所以,老师还会再次批改
L2019-12-28 14:22:371楼
我是自己写的