NO2/*学习记录*/--模仿百度首页(纯HTML+css)

成果图

1

------------导航栏HTML代码------------

    <!-- --导航栏-- -->
    <!-- class在css里用 . 做前缀,id用 # 做前缀 -->
    <div class="nav">
        <div class="navleft">
            <!-- 超链接的href后面存放的是地址也可以是内部链接
                target:(_parent新窗口打开_self是在当前窗口打开,不写默认为_self) -->
            <a href="#" target="_parent">新闻</a>
            <a href="#">hao123</a>
            <a href="#">地图</a>
            <a href="#">贴吧</a>
            <a href="#">视频</a>
            <a href="#">图片</a>
            <a href="#">网盘</a>
            <div class="dropdown">
                <a href="#" class="dropbtn">更多</a>
                <div class="dropdown-content">
                    <ul>
                        <!-- src存放的是图片地址内部外部都ok
                        alt是图片替代文字 -->
                        <li class="dropdown_img"><img src="https://p.qqan.com/up/2020-10/16038656513174848.jpg" alt="">
                            <div>网盘</div>
                        </li>
                        <li class="dropdown_img"><img src="https://p.qqan.com/up/2020-10/16038656513174848.jpg" alt="">
                            <div>知到</div>
                        </li>
                        <li class="dropdown_img"><img src="https://p.qqan.com/up/2020-10/16038656513174848.jpg" alt="">
                            <div>百科</div>
                        </li>
                        <li class="dropdown_img"><img src="https://p.qqan.com/up/2020-10/16038656513174848.jpg" alt="">
                            <div>健康</div>
                        </li>
                        <li class="dropdown_img"><img src="https://p.qqan.com/up/2020-10/16038656513174848.jpg" alt="">
                            <div>音乐</div>
                        </li>
                        <li class="dropdown_img"><img src="https://p.qqan.com/up/2020-10/16038656513174848.jpg" alt="">
                            <div>经验</div>
                        </li>
                        <li class="dropdown_img"><img src="https://p.qqan.com/up/2020-10/16038656513174848.jpg" alt="">
                            <div>宝宝知道</div>
                        </li>
                        <li class="dropdown_img"><img src="https://p.qqan.com/up/2020-10/16038656513174848.jpg" alt="">
                            <div>文库</div>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="navright">
            <a href="">设置</a>
            <div class="but"> <a href="#">登录</a></div>

        </div>
        <!-- 清除浮动 -->
        <div class="clear"></div>
    </div>

------------导航栏CSS代码------------

.nav {
    margin-top: 10px;
}

.navleft {
    float: left;
    margin-left: 20px;
    margin-top: 5px;
    font-size: 14px;
    font-family: "微软雅黑";
    text-decoration: none;
}

/* 设置字体样式 */
.nav a {
    color: rgb(100, 98, 98);
    margin-right: 20px;
    text-decoration: none;
}

/* 鼠标放上去变色部分 */
.nav a:hover {
    color: blue;
}

/* 容器 <div> - 需要定位下拉内容 */
.dropdown {
    position: relative;
    display: inline-block;
}

/* 下拉按钮样式 */
.dropbtn {
    color: rgb(100, 98, 98);
    /* padding: 16px; */
    font-size: 14px;
    border: none;
    /* cursor: pointer; */
    margin-right: 10px;
    margin-top: 5px;
    font-family: "微软雅黑";
}

/* 下拉内容 (默认隐藏) */
.dropdown-content {
    display: none;
    position: absolute;
    background-color: #f9f9f9;
    min-width: 160px;
    width: 300px;
    height: 200px;
    margin-left: -275px;
    text-align: center;
    padding: auto;
    box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
}

.dropdown-content li {
    list-style: none;
}

/* 在鼠标移上去后显示下拉菜单 */
.dropdown:hover .dropdown-content {
    display: block;
}

/* 当下拉内容显示后修改下拉按钮的背景颜色 */
.dropdown:hover .dropbtn {
    color: #4E6EF2;
}

.dropdown_img img {
    width: 50px;
    height: 50px;


}

.dropdown_img {
    float: left;
    line-height: 20px;
    margin-left: 5px;
    margin-right: 7px;
    margin-top: 10px;
}

.navright {
    float: right;
    margin-right: 20px;
    margin-top: 5px;
    font-size: 14px;
    font-family: "微软雅黑";
    text-decoration: none;
}

.but {
    text-align: center;
    background-color: #4E6EF2;
    float: right;
    border-radius: 5px 5px 5px 5px;
    width: 50px;
}

.but a {
    color: white;
    display: inline-block;
    margin: 0 auto;
}

/* 清除浮动 */
.clear {
    clear: both;
}


2

------------搜索栏HTML代码------------

    <!-- 搜索栏 -->
    <nav>
        <div class="logo">
            <a href="www.baidu.com"><img src="https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png"
                    alt=""></a>
        </div>
        <div class="search">
            <input type="text">
            <span><img id="po"
                    src="https://pic.peo.pw/a/2022/09/20/63292c1c3cc45.png"
                    alt=""></span>
            <button>百度一下</button>
        </div>
    </nav>



------------导航栏CSS代码------------

/* 搜索栏 */

nav{
    width: 100%;
    height: 200px;
  }

  .logo{
    text-align: center;
  }

  .logo img{
    width: 215px;
    height: 110px;
  }

  .search{
    width: 750px;
    height: 50px;
    margin: auto;
    display: flex;
    justify-content: center;
    align-content: center;
    min-width: 750px;
    position: relative;
  }

  input{
    width: 550px;
    height: 40px;
    border-right: none;
    border-bottom-left-radius: 10px;
    border-top-left-radius: 10px;
    border-color: #f5f5f5;
    outline: none;
  }

  input:hover{
    box-shadow: 2px 2px 2px #ccc;  
  }

  input:focus{
    border-color: rgb(78, 110, 242);
  }

  .search span{
    position: absolute;
    font-size: 23px;
    top: 10px;
    right: 170px;
  }

  .search span:hover{
    color: rgb(78, 110, 242);
  }

  button{
    width: 100px;
    height: 44px;
    background-color: rgb(78, 110, 242);
    border-bottom-right-radius: 10px;
    border-top-right-radius: 10px;
    border-color: rgb(78, 110, 242);
    color: white;
    font-size: 14px;
  }

  .search_img{
    width: 90px;
    height: 30px;
    text-align: center;
    color: #ccc;
    line-height: 30px;
    border-radius: 5px;
    position: absolute;
    top: 50px;
    right: 135px;
    box-shadow: 0px 0px 3px #ccc;
    border-color: white;
    display: none;
  }

  .search:hover .search_img{
    display: block;
  }

  #po{
    width: 24px;
    height: 24px;
  }

3

------------左边推荐部分HTML代码------------

    <!-- 左边推荐部分 -->
    <div class="active">
        <div class="activeleft"><span class="tuijian">推荐</span>

            <a href=""> <img src="https://p.qqan.com/up/2020-10/16038656513174848.jpg" alt="">
                最新!美国决定不将俄列入所谓“支恐国家”名单,俄罗斯回应;泽连斯基与德国总理朔尔茨通电话
                <br><br><span style="color:rgb(116, 115, 112) ;font-size: 13px;">每日经济新闻
                    &nbsp;&nbsp;&nbsp;09-08&nbsp;&nbsp;00:02</span>
            </a>
            <a href=""><img src="https://p.qqan.com/up/2020-10/16038656513174848.jpg" alt="">
                iPhone 14可以卫星通信了!合作伙伴股价却坐了一夜过山车……<br><br><span style="color:rgb(116, 115, 112) ;font-size: 13px;">科技处日报
                    &nbsp;&nbsp;&nbsp;09-08&nbsp;&nbsp;10:25</span></a>
            <div class="activeleft_1"> <a href="">泪目!徒手刨土救出3名被埋群众,他却再也救不回父亲和妹妹……
                    <br>
                    <img src="https://p.qqan.com/up/2020-10/16038656513174848.jpg" alt="996">
                    <img src="https://p.qqan.com/up/2020-10/16038656513174848.jpg" alt="">
                    <img src="https://p.qqan.com/up/2020-10/16038656513174848.jpg" alt=""></a></div>
        </div>

------------左边推荐部分css代码------------


/* 左边推荐部分 */

.active {
    margin: 80px;
    width: 1200px;
    margin-left: 200px;
    display: flex;
}

.activeleft {
    margin-top: 20px;
    float: left;
    width: 550px;
    overflow: hidden;
}

.tuijian {
    color: rgb(94, 92, 92);
}

.activeleft a {
    text-decoration: none;
    color: #000;
    font-size: 20px;
    font-weight: 500;
    float: left;
    margin-right: 20px;
    margin-top: 30px;
}

/* 鼠标移上文字变色 */
.activeleft a:hover {
    color: #4E6EF2;
}

.activeleft img {
    width: 200px;
    border-radius: 10px 10px 10px 10px;
    float: left;
    margin-right: 20px;
}

.activeleft_1 {
    color: #000;
    font-size: 20px;
    font-weight: 500;
    margin-top: 30px;
}

.activeleft_1 img {
    width: 150px;
    height: 130px;
}

4

------------右边热搜部分HTML代码------------

        <!-- 右边热搜部分 -->
        <div class="activeright">
            <span class="resou"> 百度热搜></span> <span class="right">
                <img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg1.3png.com%2F26a581cecaa450d40e9d810eeafe3be969ea.png&refer=http%3A%2F%2Fimg1.3png.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1665196251&t=1f836966bdfa7ad876c0c1230ff52376"
                    alt=""> 换一换</span><br><br>
            <span class="span_1">1</span><a href="">救灾特警得知父亲妹妹遇难后泪崩</a><br><br>
            <span class="span_2">2</span><a href="">孕妇就医被拒流产?大庆:丈夫撒谎</a><span class="re">热</span><br><br>
            <span class="span_3">3</span><a href="">中国经济迈上现代化新征程</a><span class="re">热</span><br><br>
            <span class="span_4">4</span><a href="">泸定地震已致82人遇难</a> <span class="xin">新</span><br><br>
            <span class="span_4">5</span> <a href="">广州拆二代:被“拆掉”的未来</a><br><br>
            <span class="span_4">6</span> <a href="">津巴布韦一入室劫案致中国公民死亡</a><span class="xin">新</span><br><br>
            <span class="span_4">7</span><a href="">女子开窗看热闹 整楼窗边都是脑袋</a>
        </div>
    </div>

------------右边热搜部分css代码------------

/* 右边热搜部分 */

.activeright {
    float: right;
    margin-top: 20px;
    width: 400px;
    margin-left: 150px;
}

.resou {
    color: #000;
    font-family: Arial, Helvetica, sans-serif;
    font-weight: 600;
    font-size: 20px;
}

.right {
    margin-left: 225px;
    color: rgb(94, 92, 92);
}

.right img {
    width: 15px;
    height: 15px;
}

.activeright a {
    text-decoration: none;
    color: #000;
    font-size: 17px;
}

.activeright a:hover {
    color: #4E6EF2;
}

.span_1 {
    margin-right: 15px;
    font-size: 20px;
    color: red;
    font-family: Arial, Helvetica, sans-serif;
}

.span_2 {
    margin-right: 15px;
    font-size: 20px;
    color: rgb(255, 111, 0);
    font-family: Arial, Helvetica, sans-serif;
}

.span_3 {
    margin-right: 15px;
    font-size: 20px;
    color: rgb(255, 183, 0);
    font-family: Arial, Helvetica, sans-serif;
}

.span_4 {
    margin-right: 15px;
    font-size: 20px;
    color: rgb(116, 115, 112);
    font-family: Arial, Helvetica, sans-serif;
}

.re {
    display: inline-block;
    background-color: rgb(255, 111, 0);
    color: #fff;
    margin-left: 15px;
    border-radius: 5px 5px 5px 5px;
    font-size: 15px;
    width: 20px;
    height: 20px;
    text-align: center;
    line-height: 20px;
}

.xin {
    display: inline-block;
    background-color: red;
    color: #fff;
    margin-left: 15px;
    border-radius: 5px 5px 5px 5px;
    font-size: 15px;
    width: 20px;
    height: 20px;
    text-align: center;
    line-height: 20px;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值