制作百度页面(HTML+CSS基础知识)

一、 前言

        本文是笔者自学HTML和CSS后,动手尝试完成一个百度页面的制作,只用到了HTML和CSS的基础知识,没有用到JavaScipt的知识,即是一个静态页面。

        如有建议欢迎在评论区指出!

二、页面预览

三、html代码

为了方便起见,CSS代码放在style标签内,没有单独成立文件

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>百度一下,你就知道</title>
    <style type="text/css">
        /*清除元素默认性质*/
        body { 
            margin: 0;
            padding: 0;
            list-style: none;
            text-decoration: none;
            font-size: 1;
            font-family: "宋体";
            background-color: white;
        }

        /*全部a元素的基础属性*/
        a {     
            color: #00c;
            text-decoration: none;
        }
        a:hover{
            color:red;
            text-decoration: underline;
        }

        /*顶部的行*/
        #topline {  
            text-align: right;
            font-size:20px;
            margin:10px 10px;
        }

        /*百度图标*/
        #logo {  
            margin-top: 10px;
            text-align: center;
        }

        /*百度应用*/
        #apps {  
            margin-top: 20px;
            text-align: center;
            font-size: 30px;
            font-weight: bold;
        }

        /*搜索*/
        #search {
            margin-top: 20px;
            text-align: center;
        }
        #search #enter{  /*搜索内容*/
            width:600px;
            height:30px;
            font-size: 20px;
            font-weight: 400;
            vertical-align: middle;
            border: 1px solid black;
            border-radius: 10px 10px 10px 10px;
        }
        #search #submit{  /*搜索按钮*/
            width:100px;
            height:37px;
            font-size: 20px;
            font-weight: 500; 
            vertical-align: middle;
            cursor: pointer;
            color: white;
            background-color:#3836E0;
            border: 1px solid black;
            border-radius: 10px 10px 10px 10px;
        }

        /*热搜*/
        #hotnews #title {margin-top: 50px;}
        #hotnews #title a{
            font-size: 20px;
            font-family: Arial Bold;
            font-weight: 900;
            color:black;
            margin-left: 485px;
        }
        #hotnews #hotlist{
            display: flex;
            justify-content: center;
        }
        #hotnews #hotlist ul {
            padding-top: 5px;
            width: 280px;
            display: inline-block;
        }
        #hotnews #hotlist li{
            height: 36px;
            line-height: 36px;
            font-size: 20px;
            text-align: left;
        }
        #hotnews #hotlist a{
            height: 36px;
            line-height: 36px;
            font-size: 20px;
            padding-left: 20px;
        }
        #hotnews ul{list-style-type:none;}
        #hotnews #top3{font-weight: bold;}
        #hotnews #top3 #one,#hotnews #top3 #one a{color: #cc061d;}
        #hotnews #top3 #two,#hotnews #top3 #two a{color: rgb(240, 105, 15);}
        #hotnews #top3 #three,#hotnews #top3 #three a{color: #f0a923;}
        #hotnews #else ul li,#hotnews #else ul li a{color:#72747d}

        /*底部的行*/
        #bottomline{
            margin-top: 240px;
            position: absolute;
            left: 50%;    
            transform: translateX(-50%); 
        }
    </style>
</head>
<body>
    <div id="topline">
        <a href="https://www.baidu.com/gaoji/advanced.html">设置</a>
        |
        <a href="https://passport.baidu.com/">登录</a>
    </div>
    <div id="logo">
        <a href="https://www.baidu.com/" target="_blank"><img src="https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png" title="点此进入百度官网" width="370" height="180"></a>
    </div>
    <div id="apps">
        <a href="http://news.baidu.com/" target="_blank">新闻</a>
        <a href="https://map.baidu.com/" target="_blank">地图</a>
        <a href="http://image.baidu.com/" target="_blank">图片</a>
        <a href="https://haokan.baidu.com/" target="_blank">视频</a>
        <a href="http://tieba.baidu.com/" target="_blank">贴吧</a>
        <a href="https://wenku.baidu.com/" target="_blank">文库</a>
        <a href="https://baike.baidu.com/" target="_blank">百科</a>
        <a href="https://www.baidu.com/more/" target="_blank">更多>></a>
    </div>
    <div id="search">
        <input id="enter" type="text" maxlength="25" value="最多输入20个字"/>
        <input id="submit" type="submit" value="百度一下"/>
    </div>
    <div id="hotnews">
        <div id="title">
            <a href="https://top.baidu.com/" target="_blank">百度热搜></a>
        </div>
        <div id="hotlist">
            <div id="top3">
                <ul>
                    <li id="one">1<a href="https://pranx.com/win10-update/" target="_blank">北京申奥成功</a></li>
                    <li id="two">2<a href="https://pranx.com/win10-update/" target="_blank">吴亦凡被判入狱</a></li>
                    <li id="three">3<a href="https://pranx.com/win10-update/" target="_blank">中大即将迎来100年建校</a></li>
                </ul>
            </div>
            <div id="else">
                <ul> 
                    <li id>4<a href="https://pranx.com/win10-update/" target="_blank">骑士抢七大战胜勇士</a></li>
                    <li id>5<a href="https://pranx.com/win10-update/" target="_blank">姆巴佩世界杯决赛帽子戏法</a></li>
                    <li id>6<a href="https://pranx.com/win10-update/" target="_blank">火影忍者完结</a></li>
                </ul>
            </div>
        </div>
    </div>
    <div id="bottomline">
        <a href="https://home.baidu.com/" target="_blank">关于百度</a>
         | 
        <a href="https://e.baidu.com/" target="_blank">企业推广</a>
         | 
        <a href="https://www.baidu.com/duty/" target="_blank">使用前必读</a>
         | 
        <a href="https://help.baidu.com/" target="_blank">帮助中心</a>
         | 
        <a href="https://beian.mps.gov.cn/#/query/webSearch" target="_blank">京公网安备11000002000001号</a>
    </div>
</body>
</html>

四、不足之处

  • 由于设置“百度热搜”的时候使用的是margin-left: 485px,所以这一行字将与页面的左边缘保持485px的距离,不会随页面放缩而改变,达不到预期效果
    #hotnews #title a{
                font-size: 20px;
                font-family: Arial Bold;
                font-weight: 900;
                color:black;
                margin-left: 485px;
            }

  • 笔者尚不知道如何得到正确的像素值,目前都是估计数值大小,观察页面效果来判断是否正确,所以出现许多奇奇怪怪的像素值
  • 笔者尚不知道如何将一段文字放到页面底部的中央,所以还是使用了margin-top: 240px,如果还需要在两个块之间添加东西,则需要改变像素值,十分麻烦
    ​
    #bottomline{
                margin-top: 240px;
                position: absolute;
                left: 50%;    
                transform: translateX(-50%); 
            }
    
    ​

五、后续学习和改进

         输入文本后,点击百度搜索应该会跳转到相关页面,同时百度热搜这一块应该是时刻更新的,而不是通过文本设定的,都需要用到JavaScript的知识

  • 16
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,以下是一个简单的风景名胜页面HTMLCSS代码示例: HTML代码: ```html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>风景名胜页面</title> <link rel="stylesheet" href="style.css"> </head> <body> <header> <h1>风景名胜页面</h1> </header> <nav> <ul> <li><a href="#">首页</a></li> <li><a href="#">景点介绍</a></li> <li><a href="#">旅游攻略</a></li> <li><a href="#">联系我们</a></li> </ul> </nav> <main> <section> <h2>景点介绍</h2> <p>这里是景点介绍的内容。</p> </section> <section> <h2>旅游攻略</h2> <p>这里是旅游攻略的内容。</p> </section> </main> <footer> <p>版权所有 © 2021 风景名胜页面</p> </footer> </body> </html> ``` CSS代码: ```css /* 页面布局 */ body { margin: 0; padding: 0; font-family: Arial, sans-serif; background-color: #f2f2f2; } header { background-color: #333; color: #fff; text-align: center; padding: 20px; } nav { background-color: #ccc; text-align: center; padding: 10px; } nav ul { list-style: none; margin: 0; padding: 0; } nav li { display: inline-block; margin: 0 10px; } nav a { text-decoration: none; color: #333; padding: 5px 10px; border: 1px solid #999; border-radius: 5px; } nav a:hover { background-color: #999; color: #fff; } main { padding: 20px; } section { margin-bottom: 20px; } h2 { color: #333; } /* 页脚 */ footer { background-color: #333; color: #fff; text-align: center; padding: 10px; } ``` 在这个示例中,我们使用了HTML5中的语义标签来定义页面的结构,包括`header`、`nav`、`main`、`section`和`footer`。同时,我们也引入了CSS样式来控制页面的布局和样式。你可以根据自己的需求修改代码中的内容和样式,以适应你的页面

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值