Blogger Information
Blog 16
fans 2
comment 0
visits 20028
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
简单仿百度搜索首页
肖傲的博客
Original
1708 people have browsed it

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. <!-- 引入css样式 -->
  7. <link rel="stylesheet" href="css/index.css" />
  8. <!-- 引入图标 -->
  9. <link rel="stylesheet" href="css/iconfont.css">
  10. <title>仿百度</title>
  11. </head>
  12. <body>
  13. <!-- 页眉 -->
  14. <header>
  15. <ul class="header-left">
  16. <li><a href="#" target="_blank">新闻</a></li>
  17. <li><a href="#" target="_blank">hao123</a></li>
  18. <li><a href="#" target="_blank">地图</a></li>
  19. <li><a href="#" target="_blank">视频</a></li>
  20. <li><a href="#" target="_blank">贴吧</a></li>
  21. <li><a href="#" target="_blank">学术</a></li>
  22. <li><a href="#" target="_blank">更多</a></li>
  23. </ul>
  24. <div class="header-right">
  25. <a href="">抗击疫情</a>
  26. <span>设置</span>
  27. <a href="">登录</a>
  28. </div>
  29. </header>
  30. <!-- 中间 -->
  31. <div class="logo">
  32. <a href=""><img src="logo1.png" alt=""></a>
  33. </div>
  34. <div class="search">
  35. <span class="iconfont icon-xiangji1 zx" ></span>
  36. <input type="text" name="" />
  37. <a href="">百度一下</a>
  38. </div>
  39. <!-- 榜单区 -->
  40. <div class="hot-head">
  41. <a href="" class="hot-title">百度热搜榜</a>
  42. <a href="" class="hot-change">
  43. <span class="iconfont icon-zhuanhuan- zh"></span>
  44. <span>换一换</span>
  45. </a>
  46. </div>
  47. <div class="hot-list">
  48. <div class="hot-left">
  49. <ul>
  50. <li>
  51. <span class="iconfont icon-1_square_solid number1"></span>
  52. <a href="">90后姑娘熬夜战疫胖了十几斤</a>
  53. <span class="iconfont icon-re1 re1" ></span>
  54. </a>
  55. </li>
  56. <li>
  57. <span class="iconfont icon-2_square_solid number2"></span>
  58. <a href="#">大碗宽面的姐姐们评论张萌</a>
  59. <span class="iconfont icon-xin1 xin1"></span>
  60. </li>
  61. <li>
  62. <span class="iconfont icon-3_square_solid number3"></span>
  63. <a href="#">教育部给本科教学打分</a>
  64. </li>
  65. </ul>
  66. </div>
  67. <div class="hot-right">
  68. <ul>
  69. <li>
  70. <span class="iconfont icon-4_square_solid number4"></span>
  71. <a href="">全国人大代表申纪兰逝世</a>
  72. </a>
  73. </li>
  74. <li>
  75. <span class="iconfont icon-5_square_solid number4"></span>
  76. <a href="#">北京新增14例确诊病例</a>
  77. </li>
  78. <li>
  79. <span class="iconfont icon-6_square_solid number4"></span>
  80. <a href="#">快乐大本营选常驻新人</a>
  81. </li>
  82. </ul>
  83. </div>
  84. </div>
  85. <!-- 页脚 -->
  86. <footer>
  87. <div class="footer-left">
  88. <a href="" target="_blank">设为首页</a>
  89. <a href="" target="_blank">关于百度</a>
  90. <a href="" target="_blank">About Baidu</a>
  91. <a href="" target="_blank">百度营销</a>
  92. <a href="" target="_blank">使用百度前必读</a>
  93. <a href="" target="_blank">意见反馈</a>
  94. <a href="" target="_blank">帮助中心</a>
  95. </div>
  96. <div class="footer-right">
  97. <span>©2020 Baidu&nbsp;&nbsp;&nbsp;&nbsp;(京)-经营性-2017-0020</span>
  98. <a href="">京公网安备11000002000001号</a>
  99. <span>京ICP证030173号</span>
  100. </div>
  101. </footer>
  102. </body>
  103. </html>

css代码:

  1. * {
  2. /* 初始化样式 */
  3. margin: 0;
  4. padding: 0;
  5. box-sizing: border-box;
  6. }
  7. /* 去a标签除下划线 */
  8. a {
  9. text-decoration: none;
  10. font-size: 13px;
  11. color: #222;
  12. }
  13. li {
  14. list-style: none;
  15. }
  16. /* 设置为弹性容器,并垂直排列 */
  17. html,
  18. body {
  19. display: flex;
  20. flex-direction: column;
  21. height: 100%;
  22. }
  23. /* 头部区域 */
  24. header {
  25. display: flex;
  26. min-width: 1265px;
  27. height: 60px;
  28. align-items: center;
  29. /* 水平方向靠两边排列 */
  30. justify-content: space-between;
  31. }
  32. /* 左边部分 */
  33. header > .header-left {
  34. display: flex;
  35. /* 居中对齐 */
  36. align-items: center;
  37. height: 60px;
  38. /* 左外边距20px */
  39. margin-left: 20px;
  40. }
  41. header > .header-left > li > a {
  42. padding: 0 15px;
  43. }
  44. header > .header-left > li > a:hover {
  45. color: #4e71f2;
  46. }
  47. /* 右边部分 */
  48. header > .header-right {
  49. display: flex;
  50. /* 居中对齐 */
  51. align-items: center;
  52. height: 60px;
  53. /* 左外边距20px */
  54. margin-right: 23px;
  55. }
  56. header > .header-right > a,
  57. span {
  58. padding: 3px 14px;
  59. font-size: 13px;
  60. }
  61. header > .header-right > a:first-of-type {
  62. color: #f63051;
  63. }
  64. header > .header-right > a:first-of-type:hover {
  65. color: #4e71f2;
  66. }
  67. header > .header-right > a:last-of-type {
  68. background-color: #4e71f2;
  69. border-radius: 6px;
  70. height: 25px;
  71. color: #eef2fe;
  72. margin: 0 10px;
  73. }
  74. header > .header-right > span:hover {
  75. color: #4e71f2;
  76. }
  77. /* logo部分 */
  78. .logo {
  79. display: flex;
  80. align-content: center;
  81. margin: 0 auto;
  82. }
  83. .logo > a > img {
  84. height: 129px;
  85. width: 270px;
  86. }
  87. /* 搜索区 */
  88. .search {
  89. display: flex;
  90. justify-content: center;
  91. line-height: 44px;
  92. position: relative;
  93. }
  94. .search > input {
  95. width: 546px;
  96. height: 44px;
  97. border: 2px solid #a7aab5;
  98. border-right: none;
  99. border-radius: 10px 0 0 10px;
  100. }
  101. /* 定位后通过反向高度和内边距撑开到想要的位置 */
  102. .search > span {
  103. position: absolute;
  104. /* border: 1px solid red; */
  105. padding-left: 400px;
  106. top: -25%;
  107. }
  108. /* 设置照相机图标大小颜色 */
  109. .search > .zx {
  110. font-size: 25px;
  111. color: #a7aab5;
  112. }
  113. .search > a {
  114. height: 44px;
  115. width: 108px;
  116. text-align: center;
  117. background-color: #4e6ef2;
  118. color: #eef2fe;
  119. font-size: 17px;
  120. border-radius: 0 15px 15px 0;
  121. }
  122. /* 鼠标悬停样式 */
  123. .search > a:hover {
  124. background-color: #4662d9;
  125. }
  126. .search > .zx:hover {
  127. color: #4e6ef2;
  128. }
  129. .search > input:hover {
  130. border: 2px solid #626675;
  131. border-right: none;
  132. }
  133. /* 热搜区 */
  134. .hot-head {
  135. width: 654px;
  136. display: flex;
  137. /* 主轴为水平靠两端边对齐排列 */
  138. justify-content: space-between;
  139. margin: 25px auto;
  140. }
  141. .hot-head > a:first-of-type {
  142. font-size: 14px;
  143. }
  144. .hot-head > a > span:last-of-type {
  145. font-size: 13px;
  146. color: #9195a3;
  147. /* 字体变细 */
  148. font: 400;
  149. }
  150. .hot-head > a > .zh {
  151. font-size: 16px;
  152. color: #9195a3;
  153. margin-right: -28px;
  154. }
  155. /* 列表区 */
  156. .hot-list {
  157. display: flex;
  158. width: 654px;
  159. height: 100%;
  160. margin: 5px auto;
  161. }
  162. /* 右边 */
  163. .hot-list > .hot-left {
  164. display: flex;
  165. flex-grow: 1;
  166. margin-right: 50px;
  167. }
  168. .hot-list > .hot-left > ul > li {
  169. padding-top: 10px;
  170. }
  171. .hot-list > .hot-left > ul > li > a {
  172. font-size: 14px;
  173. line-height: 20px;
  174. text-align: center;
  175. }
  176. /* 左边 */
  177. .hot-list > .hot-right {
  178. display: flex;
  179. flex-grow: 1;
  180. }
  181. .hot-list > .hot-right > ul > li {
  182. padding-top: 10px;
  183. }
  184. .hot-list > .hot-right > ul > li > a {
  185. font-size: 14px;
  186. line-height: 20px;
  187. text-align: center;
  188. }
  189. /* 鼠标悬停样式 */
  190. .hot-list > .hot-left > ul > li > a:hover {
  191. color: #4e6ef2;
  192. }
  193. .hot-list > .hot-right > ul > li > a:hover {
  194. color: #4e6ef2;
  195. }
  196. /* 图标样式 */
  197. .hot-list > .hot-left > ul > li > .number1 {
  198. color: #fcd533;
  199. }
  200. .hot-list > .hot-left > ul > li > .re1 {
  201. color: #faab06;
  202. }
  203. .hot-list > .hot-left > ul > li > .number2 {
  204. color: #b9d5f3;
  205. }
  206. .hot-list > .hot-left > ul > li > .xin1 {
  207. color: #ff4589;
  208. }
  209. .hot-list > .hot-left > ul > li > .number3 {
  210. color: #ead1bb;
  211. }
  212. .hot-list > .hot-right > ul > li > .number4 {
  213. color: #9195a3;
  214. }
  215. /* 页脚区 */
  216. footer {
  217. display: flex;
  218. min-width: 1265px;
  219. height: 40px;
  220. align-items: center;
  221. justify-content: space-between;
  222. background-color: #fafafa;
  223. }
  224. /* 页脚区 */
  225. footer > .footer-left {
  226. margin-left: 14px;
  227. }
  228. footer > .footer-left > a {
  229. font-size: 12px;
  230. color: #9e95ad;
  231. padding: 13px;
  232. }
  233. footer > .footer-right {
  234. margin-right: 14px;
  235. }
  236. footer > .footer-right > a,
  237. span {
  238. font-size: 12px;
  239. color: #9e95ad;
  240. padding: 13px;
  241. }
  242. /* 鼠标悬停样式 */
  243. footer > .footer-left > a:hover {
  244. color: #000;
  245. }
  246. footer > .footer-right > a:hover {
  247. color: #000;
  248. }

总结:flex布局可以快速让页面向两边靠边对齐。弹性布局中定位使用不太掌握。目前只能写简单页面,复杂的还要多学习下。多后面要多练习写几个其他网页,争取让自己多熟练一点。页面小小,代码不少。要想掌握,还需练好。

Correcting teacher:天蓬老师天蓬老师

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!