博客列表 >仿今日头条首页

仿今日头条首页

一个好人
一个好人原创
2023年03月22日 16:47:22641浏览
  1. <div class="header">
  2. <div class="search">
  3. <div class="keys">
  4. <span class="iconfont icon-sousuo">&nbsp;&nbsp;</span>
  5. <span>习主席访问俄罗斯</span>
  6. </div>
  7. <div class="publish">
  8. <span class="iconfont icon-jiahao"></span>
  9. <span class="desc">发布</span>
  10. </div>
  11. </div>
  12. <div class="navs0">
  13. <div class="navs">
  14. <a href="">关注</a>
  15. <a href="" class="active">推荐</a>
  16. <a href="">热榜</a>
  17. <a href="">发现</a>
  18. <a href="">视频</a>
  19. <a href="">防疫</a>
  20. <a href="">图片</a>
  21. </div>
  22. <span class="iconfont icon-zhuanfa"></span>
  23. </div>
  24. </div>
  25. <div class="main">
  26. <div class="rec-list">
  27. <a href="" class="item">
  28. <span class="title">习近平同俄罗斯总统普京举行会谈</span>
  29. <div class="desc">
  30. <span class="tag">置顶</span>
  31. <div class="other">
  32. <span>已关注</span>
  33. <span>央视新闻</span>
  34. <span>235条评论</span>
  35. </div>
  36. </div>
  37. </a>
  38. </div>
  39. <div class="img1-list">
  40. <a href="" class="item">
  41. <div class="left">
  42. <div class="title">泽连斯基恐提前逃亡!4万乌军陷入包围圈</div>
  43. <div class="desc">
  44. <span class="author">航航观历史</span>
  45. <span class="replay-num">100条评论</span>
  46. <span class="time">17小时前</span>
  47. </div>
  48. </div>
  49. <img src="static/images/img1.png" class="right">
  50. </a>
  51. </div>
  52. <div class="img2-list">
  53. <a href="" class="item">
  54. <div class="title">泽连斯基恐提前逃亡!4万乌军陷入包围圈</div>
  55. <div class="imgs">
  56. <img src="static/images/img1.png" alt="">
  57. <img src="static/images/img1.png" alt="">
  58. <img src="static/images/img1.png" alt="">
  59. </div>
  60. </a>
  61. </div>
  62. <div class="video-list">
  63. <a href="" class="item">
  64. <div class="title">古筝:小雨沙沙</div>
  65. <video src="static/video/video.mp4" controls></video>
  66. </a>
  67. </div>
  68. </div>
  69. <div class="footer">
  70. <a href="" class="active">
  71. <span class="iconfont icon-zhuye"></span>
  72. <span>首页</span>
  73. </a>
  74. <a href="" class="">
  75. <span class="iconfont icon-24gl-play"></span>
  76. <span>视频</span>
  77. </a>
  78. <a href="" class="">
  79. <span class="iconfont icon-liuyan"></span>
  80. <span>留言</span>
  81. </a>
  82. <a href="" class="">
  83. <span class="iconfont icon-yonghu"></span>
  84. <span>登录</span>
  85. </a>
  86. </div>
  1. 页眉
  2. .header{
  3. position: fixed;
  4. left: 0;
  5. right: 0;
  6. top: 0;
  7. border-bottom: 1px solid #efefef;
  8. /* 确保页眉在顶层 */
  9. z-index: 888;
  10. background-color: #fff;
  11. }
  12. .header .search{
  13. background-color: rgb(247, 73, 73);
  14. padding: 0.08rem 0rem 0.08rem 0.15rem;
  15. display: grid;
  16. grid-template-columns: 1fr 0.6rem;
  17. }
  18. .header .search .keys{
  19. height: 0.45rem;
  20. background-color: #fff;
  21. border-radius: 1.5rem;
  22. padding-left: 0.18rem;
  23. display: flex;
  24. place-items: center;
  25. }
  26. .header .search .publish{
  27. display: grid;
  28. place-items: center;
  29. color: #fff;
  30. font-size: 0.01rem;
  31. }
  32. .icon-jiahao{
  33. font-size: 0.25rem !important
  34. }
  35. .header .navs0{
  36. display: grid;
  37. grid-template-columns: 1fr 0.2rem;
  38. padding: 0.05rem 0.02rem 0.25rem;
  39. }
  40. .header .navs0 .navs{
  41. display: flex;
  42. place-content: space-around;
  43. position: fixed;
  44. left: 0;
  45. right: 0;
  46. }
  47. .header .navs0 .icon-zhuanfa{
  48. display: flex;
  49. position: fixed;
  50. right: 0;
  51. /* padding-right: 0.1rem; */
  52. width: 0.35rem;
  53. height: 0.25rem;
  54. background-color: #fff;
  55. place-content: center;
  56. color: #ccc;
  57. }
  58. .header .navs0 .navs a.active{
  59. color: rgb(247, 73, 73);
  60. }
  61. .header .navs0 .navs a{
  62. position: relative;
  63. }
  64. .header .navs0 .navs a.active::after{
  65. content: '';
  66. position: absolute;
  67. left: 0.05rem;
  68. width: 0.22rem;
  69. height: 0.03rem;
  70. bottom: -0.04rem;
  71. background-color: rgb(247, 73, 73);
  72. }
  73. .footer {
  74. position: fixed;
  75. left: 0;
  76. bottom: 0;
  77. right: 0;
  78. background-color: #efefef;
  79. display: flex;
  80. place-content: space-around;
  81. }
  82. 页脚
  83. .footer a{
  84. display: grid;
  85. place-items: center;
  86. font-size: 0.12rem;
  87. }
  88. .footer a .iconfont{
  89. font-size: 0.25rem;
  90. }
  91. .footer a.active{
  92. color: rgb(247, 73, 73);
  93. }
  94. main部分:
  95. .main{
  96. min-height: 2000px;
  97. /* border: 1px solid #000; */
  98. position: relative;
  99. top: 1rem;
  100. /* padding-bottom: 0.6rem; */
  101. }
  102. .main .rec-list .item{
  103. display: block;
  104. margin-top: 0.05rem;
  105. }
  106. .main .rec-list .item .desc{
  107. display: flex;
  108. font-size: 0.12rem;
  109. gap: 0.1rem;
  110. }
  111. .main .rec-list .item .desc .tag{
  112. color: rgb(247, 73, 73);
  113. }
  114. .main .rec-list .item .desc .other{
  115. color: #ccc;
  116. gap: 0.1rem;
  117. }
  118. /* 左边文字+右边图片 */
  119. .main .img1-list .item{
  120. display: grid;
  121. grid-template-columns: 1fr 1.3rem;
  122. gap: 0.2rem;
  123. margin-top: 0.1rem;
  124. }
  125. .main .img1-list .item .left{
  126. display: grid;
  127. place-content: space-between;
  128. }
  129. .main .img1-list .item .left .desc{
  130. font-size: 0.12rem;
  131. color: #ccc;
  132. }
  133. /* 文本+三张图片 */
  134. .main .img2-list .item{
  135. display: block;
  136. margin-top: 0.1rem;
  137. }
  138. .main .img2-list .item .imgs{
  139. display: grid;
  140. grid-template-columns: repeat(3, 1fr);
  141. gap: 0.05rem;
  142. }
  143. /* 文字+视频 */
  144. .main .video-list .item{
  145. display: block;
  146. margin-top: 0.1rem;
  147. }
  148. 重置部分:
  149. *{
  150. margin: 0;
  151. padding: 0;
  152. box-sizing: border-box;
  153. }
  154. a{
  155. text-decoration: none;
  156. color: #555;
  157. }
  158. /* 适应设备宽度 */
  159. html{
  160. font-size: calc(100vw / 3.75);
  161. }
  162. /* 字号重置 */
  163. body{
  164. font-size: 0.16rem;
  165. color: #333;
  166. background-color: #fff;
  167. /* 页面水平居中 */
  168. margin: 0 auto;
  169. padding: 0 0.15rem;
  170. }
  171. /* 外部资源适应屏幕宽度 */
  172. body img,
  173. body video{
  174. width: 100%;
  175. }
  176. /* 媒体查询 可选 */
  177. @media (max-width:320px) {
  178. html{
  179. font-size: 85px;
  180. }
  181. }
  182. @media (min-width:640px) {
  183. html{
  184. font-size: 170px;
  185. }
  186. }

效果图1
效果图2

总结:

完成了一个比较完整的手机网页,边看视频边做还好,如果完全自己去恐怕要很久,导航栏的右边悬浮了一个小图标,老师没介绍,自己弄做了好久。

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议