仿"今日头条"首页

编辑: admin 分类: 电脑知识 发布时间: 2023-06-14 来源:互联网
仿”今日头条”首页一、页眉结构分析

页面整体分三个部分:页眉、主体、页脚,其中

  • 页眉:固定在顶部,可以采用固定定位来实现
  • 页脚:固定在底部,同样采用固定定位来实现
  • 主体:中间部分,其上部和下部占据了页眉和页脚的文档流位置而被遮挡,可以采用相对定位并设置 top 值解决被页眉遮挡的部分;通过设置 padding-bottom 解决被页脚遮挡的部分
二、HTML 文档结构
  1. <!doctype html>
  2. <html lang="cn-ZH">
  3. <head>
  4. ......
  5. <link rel="stylesheet" href="mobile.css">
  6. </head>
  7. <body>
  8. <header>
  9. <div class="search">
  10. <div class="keys">
  11. <span class="iconfont icon-sousuo"></span>
  12. <span>习近平主席访问俄罗斯</span>
  13. </div>
  14. <div class="publish">
  15. <span class="iconfont icon-jiahao1"></span>
  16. <span>发布</span>
  17. </div>
  18. </div>
  19. <div class="navs">
  20. <a href="" class="active">推荐</a>
  21. <a href="">科技</a>
  22. <a href="">数码</a>
  23. <a href="">军事</a>
  24. <a href="">科技</a>
  25. </div>
  26. </header>
  27. <main>
  28. <div class="recList">
  29. <a href="" class="item">
  30. <span class="title">习近平主席仿俄第一天,这些信息值得关注</span>
  31. <div class="desc">
  32. <span class="tag">置顶</span>
  33. <div class="other">
  34. <span>已关注</span>
  35. <span>央视新闻</span>
  36. <span>1234条评论</span>
  37. </div>
  38. </div>
  39. </a>
  40. ......
  41. </div>
  42. <div class="img1-list">
  43. <a href="" class="item">
  44. <div class="left">
  45. <div class="title">中方将会如何推动俄乌实现停火?外交部回应</div>
  46. <div class="desc">
  47. <span class="author">外交部</span>
  48. <span class="reply-num">666条评论</span>
  49. <span class="time">10小时前</span>
  50. </div>
  51. </div>
  52. <img src="img_1.png" alt="" class="right">
  53. </a>
  54. ......
  55. </div>
  56. <div class="img2-list">
  57. <a href="" class="item">
  58. <div class="title">华为何刚揭秘折叠新机黑科技 有三个方面很特殊</div>
  59. <div class="images">
  60. <img src="img_3.png" alt="">
  61. <img src="img_2.png" alt="">
  62. <img src="img.png" alt="">
  63. </div>
  64. </a>
  65. ......
  66. </div>
  67. </main>
  68. <footer>
  69. <a href="" class="active">
  70. <span class="iconfont icon-zhuye"></span>
  71. <span>首页</span>
  72. </a>
  73. <a href="">
  74. <span class="iconfont icon-bofang"></span>
  75. <span>视频</span>
  76. </a>
  77. <a href="">
  78. <span class="iconfont icon-xiaozu"></span>
  79. <span>小组</span>
  80. </a>
  81. <a href="">
  82. <span class="iconfont icon-31wode"></span>
  83. <span>我的</span>
  84. </a>
  85. </footer>
  86. </body>
  87. </html>
三、CSS 样式
  1. @import url(//at.alicdn.com/t/c/font_3961095_nhhkymnxkm.css);
  2. *{ margin: 0; padding: 0; box-sizing: border-box; }
  3. html{ font-size: calc(100vw / 3.75); }
  4. body{ font-size: 0.16rem; }
  5. header{
  6. position: fixed;
  7. top: 0;
  8. left: 0;
  9. right: 0;
  10. z-index: 999;
  11. border-bottom: 1px solid #ccc;
  12. background-color: white;
  13. }
  14. header .search{
  15. background: red;
  16. display: grid;
  17. grid-template-columns: 1fr 0.5rem;
  18. padding: 0.08rem 0.15rem;
  19. }
  20. header .search .keys{
  21. background: #fff;
  22. border-radius: 0.5rem;
  23. display: flex;
  24. place-items: center;
  25. }
  26. header .search .keys .icon-sousuo{
  27. font-size: 0.16rem;
  28. padding-left: 0.08rem;
  29. }
  30. header .search .publish{
  31. color: white;
  32. place-self: end;
  33. display: grid;
  34. place-items: center;
  35. }
  36. header .search .publish .icon-jiahao1{
  37. font-size: 0.16rem;
  38. }
  39. header .navs{
  40. display: flex;
  41. place-content: space-around;
  42. padding: 0.1rem 0 0.05rem;
  43. }
  44. header .navs a{
  45. text-decoration: none;
  46. color: #030303;
  47. position: relative;
  48. }
  49. header .navs a.active{
  50. color: red;
  51. }
  52. header .navs a.active::after{
  53. content: '';
  54. position: absolute;
  55. left: 0;
  56. bottom: -0.04rem;
  57. width: 0.32rem;
  58. height: 0.02rem;
  59. background-color: red;
  60. }
  61. main{
  62. position: relative;
  63. top: 0.9rem;
  64. margin: 0 0.2rem;
  65. padding-bottom: 0.6rem;
  66. }
  67. main .recList .item{
  68. text-decoration: none;
  69. color: #030303;
  70. display: block;
  71. margin-top: 0.1rem;
  72. }
  73. main .recList .item .desc{
  74. font-size: x-small;
  75. display: flex;
  76. gap: 0.1rem;
  77. }
  78. main .recList .item .desc .tag{
  79. color: red;
  80. }
  81. main .recList .item .desc .other{
  82. color: #ccc;
  83. }
  84. main .img1-list a{
  85. text-decoration: none;
  86. color: #030303;
  87. margin-top: 0.1rem;
  88. }
  89. main .img1-list .item{
  90. display: grid;
  91. grid-template-columns: 1fr 1.3rem;
  92. gap: 0.2rem;
  93. }
  94. main .img1-list .item .left{
  95. display: grid;
  96. place-content: space-between;
  97. }
  98. main .img1-list .item .left .desc{
  99. font-size: x-small;
  100. color: #ccc;
  101. }
  102. main .img1-list .item .right{
  103. width: 100%;
  104. }
  105. main .img2-list .item{
  106. display: block;
  107. margin: 0.1rem 0;
  108. text-decoration: none;
  109. color: #030303;
  110. }
  111. main .img2-list .item .images{
  112. display: grid;
  113. grid-template-columns: repeat(3, 1fr);
  114. gap: 0.05rem;
  115. }
  116. main .img2-list .item .images img{
  117. width: 100%;
  118. }
  119. footer{
  120. position: fixed;
  121. bottom: 0;
  122. left: 0;
  123. right: 0;
  124. display: flex;
  125. place-content: space-around;
  126. background-color: #efefef;
  127. padding: 0.08rem 0;
  128. }
  129. footer a{
  130. text-decoration: none;
  131. display: grid;
  132. place-items: center;
  133. font-size: x-small;
  134. }
  135. footer a .iconfont{
  136. font-size: 0.2rem;
  137. }
  138. footer a.active{
  139. color: red;
  140. }
四、页面显示效果

【文章原创作者:阿里云代理 http://www.558idc.com/aliyun.html处的文章,转载请说明出处】