Blogger Information
Blog 12
fans 0
comment 0
visits 5388
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
仿今日头条首页
汉邦
Original
290 people have browsed it

首页整体分为三个部分:页面,主体,页脚.

页眉代码:

  1. 分别引用外部CSS文件:

    1. <link rel="stylesheet" href="static/css/reset.css">
    2. <link rel="stylesheet" href="static/css/header.css">
    3. <link rel="stylesheet" href="static/css/footer.css">
    4. <link rel="stylesheet" href="static/css/main.css">
    5. <link rel="stylesheet" href="static/font_icon/iconfont.css">

    其中 reset.css 初始化代码如下:

    1. .footer {
    2. /* 绝对定位 */
    3. position: fixed;
    4. left: 0;
    5. right: 0;
    6. bottom: 0;
    7. background-color: #efefef;
    8. display: flex;
    9. /* 分散对齐 */
    10. place-content: space-around;
    11. z-index: 999;
    12. }
    13. .footer a {
    14. /* 垂直排列,居中对齐 */
    15. display: grid;
    16. place-items: center;
    17. font-size: x-small;
    18. }
    19. /* 图标放大 */
    20. .footer a .iconfont {
    21. font-size: x-large;
    22. }
    23. /* 激活样式 */
    24. .footer a.active {
    25. color: red;
    26. }
  2. 页眉代码:

    1. <!-- 页眉 -->
    2. <div class="header">
    3. <!-- 1.搜索框 -->
    4. <div class="search">
    5. <!-- 1.1关键字输入框 left -->
    6. <div class="keys">
    7. <!-- 放大镜:字体图标 -->
    8. <span class="iconfont icon-fangdajing"></span>
    9. <!-- 关键字-预置的 -->
    10. <span>“天网2023”行动启动</span>
    11. </div>
    12. <!-- 1.2 发布按钮,right -->
    13. <div class="publish">
    14. <!-- 字体图标 -->
    15. <span class="iconfont icon-jiahao"></span>
    16. <span>发布</span>
    17. </div>
    18. </div>
    19. <!-- 2.导航组 -->
    20. <div class="navs">
    21. <a href="">关注</a>
    22. <a href="" class="active">推荐</a>
    23. <!-- 高亮 -->
    24. <a href="">热榜</a>
    25. <a href="">发现</a>
    26. <a href="">视频</a>
    27. <a href="">防疫</a>
    28. <div class="key">
    29. <span class="iconfont icon-zhuanfa"></span>
    30. </div>
    31. </div>
    32. </div>

css代码:

  1. .header {
  2. /* 固定定位: */
  3. position: fixed;
  4. left: 0;
  5. top: 0;
  6. right: 0;
  7. /* 给导航栏设置下划线 */
  8. border-bottom: 1px solid #ccc;
  9. /* 设置层级,确保永远在最前面,不会被覆盖 */
  10. z-index: 999;
  11. background-color: #fff;
  12. }
  13. /* 搜索栏 */
  14. .header .search {
  15. background-color: red;
  16. /* 布局格式 */
  17. display: grid;
  18. grid-template-columns: 1fr 0.5rem;
  19. /* 内边距 */
  20. padding: 0.1rem 0.13rem;
  21. }
  22. /* 搜索框 */
  23. .header .search .keys {
  24. background-color: #fff;
  25. border-radius: 1.5rem;
  26. display: flex;
  27. place-items: center;
  28. padding-left: 0.15rem;
  29. }
  30. /* 发布按钮 */
  31. .header .search .publish {
  32. color: #fff;
  33. display: grid;
  34. place-items: center;
  35. font-size: large;
  36. }
  37. /* 字体图标加号放大 */
  38. .header .search .publish .icon-jiahao {
  39. font-size: x-large;
  40. }
  41. /* 列表 */
  42. .header .navs {
  43. /* 弹性布局 */
  44. display: flex;
  45. /* 分散对齐 */
  46. place-content: space-around;
  47. /* 给导航栏下划线加间距 下边0.05rem*/
  48. padding: 0.1rem 0 0.05rem;
  49. }
  50. .header .navs .key .icon_zhuanfa {
  51. display: flex;
  52. position: fixed;
  53. font-size: xx-large;
  54. right: 0;
  55. width: 0.35rem;
  56. height: 0.25rem;
  57. place-content: center;
  58. color: #ccc;
  59. }
  60. /* 激活状态 */
  61. .header .navs a.active {
  62. color: red;
  63. }
  64. /* 添加激活状态下的下划线,利用伪元素 */
  65. /* 伪元素前面使用双冒号:::before/::after */
  66. .header .navs a.active::after {
  67. content:'';
  68. /* 绝对定位 */
  69. position: absolute;
  70. left: 0;
  71. width: 0.3rem;
  72. height: 0.03rem;
  73. background-color: red;
  74. bottom: -0.03rem;
  75. }
  76. /* 宿主元素a作为绝对定位的父级 */
  77. .header .navs a {
  78. position: relative;
  79. }

3.主体代码:

  1. <div class="main">
  2. <!-- 1.文本+标签 -->
  3. <div class="rec-list">
  4. <a href="" class="item">
  5. <span class="title">中俄元首克里姆林宫会谈侧记</span>
  6. <div class="desc">
  7. <span class="tag">置顶</span>
  8. <div class="other">
  9. <span>新华网</span>
  10. <span>1万评论</span>
  11. </div>
  12. </div>
  13. </a>
  14. <a href="" class="item">
  15. <span class="title">在推动构建人类命运共同体的大道上前进</span>
  16. <div class="desc">
  17. <span class="tag">置顶</span>
  18. <div class="other">
  19. <span>人民日报</span>
  20. <span>1347评论</span>
  21. </div>
  22. </div>
  23. </a>
  24. <a href="" class="item">
  25. <span class="title">春天里的中国色,美到惊艳!</span>
  26. <div class="desc">
  27. <span class="tag">置顶</span>
  28. <div class="other">
  29. <span>人民日报</span>
  30. <span>1644评论</span>
  31. </div>
  32. </div>
  33. </a>
  34. <a href="" class="item">
  35. <span class="title">"美国人要我们跳,咱不仅问'跳多高',还来个后空翻!"</span>
  36. <div class="desc">
  37. <div class="other">
  38. <span>环球网</span>
  39. <span>166评论</span>
  40. </div>
  41. </div>
  42. </a>
  43. <a href="" class="item">
  44. <span class="title">健康中国|甲流感染期食养建议</span>
  45. <div class="desc">
  46. <div class="other">
  47. <span>头条专题</span>
  48. </div>
  49. </div>
  50. </a>
  51. </div>
  52. <!-- 2.左边文本+右边图片 -->
  53. <div class="img1-list">
  54. <a href="" class="item">
  55. <!-- 标题文本 -->
  56. <div class="left">
  57. <div class="title">还派什么大使,美国晾了我们14个月,是时候反击了</div>
  58. <div class="desc">
  59. <span class="author">默默读书君</span>
  60. <span class="replay-num">88条评论</span>
  61. <span class="time">10小时前</span>
  62. </div>
  63. </div>
  64. <!-- 图片 -->
  65. <img src="static/images/1.jpeg" class="right"></img>
  66. </a>
  67. <a href="" class="item">
  68. <!-- 标题文本 -->
  69. <div class="left">
  70. <div class="title">还派什么大使,美国晾了我们14个月,是时候反击了</div>
  71. <div class="desc">
  72. <span class="author">默默读书君</span>
  73. <span class="replay-num">88条评论</span>
  74. <span class="time">10小时前</span>
  75. </div>
  76. </div>
  77. <!-- 图片 -->
  78. <img src="static/images/1.jpeg" class="right"></img>
  79. </a>
  80. <a href="" class="item">
  81. <!-- 标题文本 -->
  82. <div class="left">
  83. <div class="title">还派什么大使,美国晾了我们14个月,是时候反击了</div>
  84. <div class="desc">
  85. <span class="author">默默读书君</span>
  86. <span class="replay-num">88条评论</span>
  87. <span class="time">10小时前</span>
  88. </div>
  89. </div>
  90. <!-- 图片 -->
  91. <img src="static/images/1.jpeg" class="right"></img>
  92. </a>
  93. </div>
  94. <!-- 3.上面文本+三张图片 -->
  95. <div class="img2-list">
  96. <a href="" class="item">
  97. <div class="title">2001年金吉奇用承诺诱捕米洛舍维奇,将其私自引渡海牙,下场如何?</div>
  98. <div class="imgs">
  99. <img src="static/images/2.jpeg" alt="">
  100. <img src="static/images/2.jpeg" alt="">
  101. <img src="static/images/2.jpeg" alt="">
  102. </div>
  103. </a>
  104. </div>
  105. </div>

CSS代码:

  1. .main {
  2. min-height: 2000px;
  3. /* border: 1px solid rgb(229, 43, 43); */
  4. /* 相对定位 */
  5. position: relative;
  6. top: 1rem;
  7. padding-bottom: 0.6rem;
  8. }
  9. /* 下划线 */
  10. .main .rec-list {
  11. border-bottom: 0.6px solid #ccc;
  12. padding: 0 0 0.05rem;
  13. }
  14. .main .rec-list .item {
  15. /* 行内元素转块级元素 */
  16. display: block;
  17. margin-top: 0.1rem;
  18. }
  19. .main .rec-list .item .desc {
  20. display: flex;
  21. font-size: xx-small;
  22. gap: 0.1rem;
  23. }
  24. .main .rec-list .item .desc .tag {
  25. color: red;
  26. }
  27. .main .rec-list .item .desc .other {
  28. color: #ccc;
  29. }
  30. /* 文本+图片 */
  31. .main .img1-list .item {
  32. display: grid;
  33. grid-template-columns: 1fr 1.3rem;
  34. gap: 0.2rem;
  35. margin-top: 0.1rem;
  36. }
  37. .main .img1-list .item .left {
  38. display: grid;
  39. place-content: space-between;
  40. }
  41. .main .img1-list .item .left .desc {
  42. color: #ccc;
  43. font-size: xx-small;
  44. }
  45. /* 上面文本+三张图片 */
  46. .main .img2-list .item .imgs {
  47. display: grid;
  48. grid-template-columns: repeat(3,1fr);
  49. gap:0.05rem;
  50. }

4.页脚

  1. <div class="footer">
  2. <a href="" class="active">
  3. <span class="iconfont icon-shouye"></span>
  4. <span>首页</span>
  5. </a>
  6. <a href="">
  7. <span class="iconfont icon-24gl-play"></span>
  8. <span>视频</span>
  9. </a>
  10. <a href="">
  11. <span class="iconfont icon-shoucang"></span>
  12. <span>商城</span>
  13. </a>
  14. <a href="">
  15. <span class="iconfont icon-yonghu"></span>
  16. <span>我的</span>
  17. </a>
  18. </div>

CSS代码:

  1. .footer {
  2. /* 绝对定位 */
  3. position: fixed;
  4. left: 0;
  5. right: 0;
  6. bottom: 0;
  7. background-color: #efefef;
  8. display: flex;
  9. /* 分散对齐 */
  10. place-content: space-around;
  11. z-index: 999;
  12. }
  13. .footer a {
  14. /* 垂直排列,居中对齐 */
  15. display: grid;
  16. place-items: center;
  17. font-size: x-small;
  18. }
  19. /* 图标放大 */
  20. .footer a .iconfont {
  21. font-size: x-large;
  22. }
  23. /* 激活样式 */
  24. .footer a.active {
  25. color: red;
  26. }

最终效果图:

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post