• 零基础学前端(五)HTML+CSS实战:模仿百度网站首页


    1. 该篇适用于从零基础学习前端的小白

    2. 初学者不懂代码得含义也要坚持模仿逐行敲代码,以身体感悟带动头脑去理解新知识

     一、实战:将百度网站首页补全

    上一篇零基础学前端(三)重点讲解 HTML-CSDN博客我们已经将顶部两侧内容已经写完。

    1. 接下来我们的目标如下图:分析对应的标签已经写在下面图片(我将百度logo涂上马赛克,主要是担心图片违规怕被封掉)

    1. <div class="main">
    2. <div class="logoBox">
    3. <img class="logo" src="./img/logo.png" />
    4. <div class="inputBox">
    5. <input />
    6. <button>百度一下button>
    7. div>
    8. div>
    9. div>
    1. <style>
    2. /*================================== 主体内容 =======================================*/
    3. .logoBox{
    4. }
    5. .logoBox .logo{
    6. width: 206px;
    7. height: 66px;
    8. }
    9. .inputBox{
    10. }
    11. /* 标签选择器:选中inputBox类下面的input */
    12. .inputBox input{
    13. width: 443px;
    14. height: 42px;
    15. border: 1px solid #ccc;
    16. }
    17. .inputBox button{
    18. background-color: #4E6EF2; /* 设置背景颜色 */
    19. color: #fff; /* 设置文字颜色 */
    20. height: 44px;
    21. border: none;
    22. padding-left: 12px;
    23. padding-right: 12px;
    24. }
    25. style>

    做出来的效果图 

     2. 确定需要改进的问题

    1. 那个缝隙不该存在,百度一下按钮,需要靠在 input输入框

    2. 百度图片的logo 应该在输入框和按钮的中间

    1. <style>
    2. /* 设置整体居中 */
    3. .logoBox{
    4. display: flex;
    5. flex-direction: column;
    6. align-items: center;
    7. }
    8. /*让按钮贴近input输入框*/
    9. .inputBox button{
    10. margin-left: -10px; /*设置一个负值就方向贴近*/
    11. }
    12. style>

    3. 继续优化细节

    我们可以看到
    1. 按钮 和 输入框 贴近后,虽然高度是一样的,效果上还是有一点偏差
    2. 输入框 和 按钮是有圆角的 

    1. <style>
    2. /*让输入框 和 按钮 对其*/
    3. .inputBox{
    4. display: flex;
    5. align-items: center;
    6. }
    7. style>
    1. <style>
    2. .inputBox input{
    3. border-radius: 5px 0 0 5px; /*设置圆角:4个值分别代表 左上角、右上角、右下角、左下角*/
    4. }
    5. .inputBox button{
    6. border-radius: 0 5px 5px 0;
    7. }
    8. style>

     效果图

    二、目标:写百度热搜

    这就是接下来我们要写得内容

    1. <div class="hotSearch">
    2. <div class="top">
    3. <div class="leftBox">
    4. <span class="title">百度热搜span>
    5. <span class="arrow">>span>
    6. div>
    7. <div class="rightBox">
    8. <img class="refresh" src="./img/refresh.png"/>
    9. <span class="huan">换一换span>
    10. div>
    11. div>
    12. <ol class="info">
    13. <li>杭州亚运会中国队开门红li>
    14. <li>打造“数字丝绸之路”li>
    15. <li>美国2009年就开始入侵华为服务器li>
    16. <li>亚运会今日赛程li>
    17. <li>12306回应节假日车票涨价li>
    18. <li>警方钓鱼演练321名大学生上钩li>
    19. ol>
    20. div>
    1. /* ============== 热搜部分 =============== */
    2. .hotSearch{
    3. display: flex;
    4. flex-direction: column;
    5. align-items: center;
    6. margin-top: 30px;
    7. }
    8. .hotSearch .top{
    9. display: flex;
    10. justify-content: space-between;
    11. align-items: center;
    12. width: 512px;
    13. }
    14. .hotSearch .top .leftBox{
    15. display: flex;
    16. align-items: center;
    17. cursor: pointer;
    18. }
    19. .hotSearch .top .leftBox .title{
    20. font-weight: 700;
    21. font-size: 14px;
    22. margin-right: 2px;
    23. }
    24. .hotSearch .top .leftBox .arrow{
    25. color: #626675;
    26. }
    27. .hotSearch .top .rightBox{
    28. display: flex;
    29. align-items: center;
    30. cursor: pointer;
    31. }
    32. .hotSearch .top .rightBox .refresh{
    33. width: 16px;
    34. height: 16px;
    35. }
    36. .hotSearch .top .rightBox .huan{
    37. font-size: 14px;
    38. color: #626675;
    39. margin-left: 2px;
    40. }
    41. .hotSearch .info{
    42. font-size: 14px;
    43. width: 512px;
    44. display: flex;
    45. flex-wrap: wrap;
    46. justify-content: space-between;
    47. }
    48. .hotSearch .info li{
    49. width: 245px;
    50. margin: 8px 0;
    51. }

    三、将代码上传到csdn,可以下载我的源码

    https://download.csdn.net/download/tengyuxin/88359310

    四、结束语

            我个人认为初学时,学的内容逻辑简单、思路清晰最重要,所以我只是挑取核心部分,初学者理解后,可直接上手项目,这就是我的思想逻辑。
     

            css知识有很多,我不建议初学者去事无巨细的学每个知识点,我的看法是,带着问题,以实践的方式先将我博客逻辑跑通,让你对前端有个整体观念(从基础到最后发布网站,别人可以访问),到时你自己补充剩余

    为了加深理解html和css,我又写了一篇HTML+CSS实战主要是模仿QQ首页的纯页面样式编写,来看看吧。

  • 相关阅读:
    R语言使用is.numeric函数判断数据对象是否是数值型
    Qt QCustomPlot介绍
    Locust学习记录5-任务属性【Task】
    动态规划:03爬楼梯
    MySQL架构MMM
    巧妙设计状态+不断对拍寻找合适贪心策略:P8341
    【kubernetes】带你入门k8s中的HPA
    docker搭建nginx+php-fpm
    Linux入门之 systemd unit 文件
    6. 标准库类型vector
  • 原文地址:https://blog.csdn.net/tengyuxin/article/details/133021039