最近在练习自己仿写一下大厂网站,就先试试美团吧,先仿写出静态页面,没有页面交互以及其他花里胡哨的效果,目前计划十天左右完成。并且要求自己每完成一部分就按时打卡总结一下,加油!注意到整个页面是居中显示的,因此可以通过padding内边距设置上下为0,左右一定值实现一个版心样式,总体将整个页面分为了三部分实现,头部、中间内容区域以及底部区域。第一天写了网站底部还有头部部分区域,实现效果如下。

Android studio编写美团我的页面代码 美团页面制作_html

1. footer区域

   可以看到底部区域的内容和边框之间有一定间隔,可以通过padding设置内边距,其次是将底部区域分为左右两个部分,

  • 左边由多行a链接组成,由于a链接是行内元素,不会换行,所以只需要用div将a链接包裹一下进行换行就可以,比较简单。
  • 右侧稍微复杂一点,分为上下两行,第一行是一个img+文字的链接,第二行则分为四个小区域也是链接,因此都需要a标签进行包裹。图片右侧文字相对于图片居中显示需要利用vertical-align: middle;另外页面中所有小图片都可以在网页源码中找到来源,可以下载下来使用。
2. header区域

   目前只实现了头部的bar和search区域。

  • bar区域利用了flex布局,定义align-items: center;上下居中,以及justify-content: space-between;两端对齐。
  • searach区域是一个img和一个input框,这个img也是可以点击的,需要用一个a链接包裹一下;而input框则需要水平居中,这里利用的是浮动+绝对定位实现的,注意到input框的四个角需要添加圆角边框属性。
3. 源码

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>上海美团网-上海美食_酒店_旅游_团购_电影_吃喝玩乐</title>
    <link rel="stylesheet" href="./index.css">
</head>
<body>
    <!-- 头部区域 -->
    <header class="header main">
        <div class="header-bar">
            <span class="header-bar-le">
                <span style="color: #666;">上海</span>
                <a href="#" class="switch">切换城市</a>
                [
                    <a href="#">彰化</a>
                    <a href="#">宜兰</a>
                    <a href="#">太仓</a>
                ]
                <a class="login" href="#">立即登录</a>
                <a class="reg" href="#">注册</a>
            </span>
            <span class="header-bar-ri">
                <a href="#">我的美团</a>
                <a href="#">手机APP</a>
                <a href="#">商家中心</a>
                <a href="#">美团规则</a>
                <a href="#">网站导航</a>
            </span>
        </div>
        <div class="header-content">
            <div class="header-content-title fl">
                <a href="#">
                    <img src="//s0.meituan.net/bs/fe-web-meituan/10afbf1/img/logo.png" alt="美团">
                </a>
            </div>
            <div class="header-content-sear fl">
                <input type="text" placeholder="搜索商家或地点">
                <button>搜索</button>
            </div>
        </div>
    </header>
    <!-- 底部区域 -->
    <footer class="footer main">
        <div class="footer-left">
            <div>
                <span>©美团网团购 meituan.com</span>              
                <a href="#">京ICP证0707091号</a>
                <a href="#">京ICP备10211739号-1</a>
            </div>
            <div>
                <a href="#">广播电视节目制作经营许可证(京)字第03889号</a>
            </div>
            <div>
                <a href="#">食品经营许可证</a>
                <a href="#">互联网药品信息服务资格证(京)-经营性-2017-0014</a>
            </div>
            <div>
                <a href="#">医疗器械网络交易服务第三方平台备案:(京)网械平台备字[2018]第00004号</a>
            </div>
            <a href="#">平台EDI许可证</a>
        </div>
        <div class="footer-right">
            <a href="#" class="footer-right-fir">
                <img src="https://p0.meituan.net/travelcube/d0289dc0a46fc5b15b3363ffa78cf6c719256.png">
                <span>京公网安备 11000002002052号</span>
            </a>
            <div class="footer-right-se">
                <a href="#">
                    <img src="https://p1.meituan.net/travelcube/3e7f8a17e55bace814166b667618b459366061.png@76h_76w_2e">
                    <span>北京三快科技有限公司</span>
                </a>
                <a class="back img1" href="#" title="备案信息" target="_blank"></a>
                <a class="back img2" href="#" title="可信网站认证" target="_blank"></a>
                <a class="back img3" href="#" title="12315消费争议" target="_blank"></a>
            </div>
        </div>
    </footer>
</body>
</html>

index.css

/* reset */
blockquote, body, button, dd, dl, dt, fieldset, form, h1, h2, h3, h4, h5, h6, hr, input, legend, li, ol, p, pre, td, textarea, th, ul {
    margin: 0;
    padding: 0;
}
span, img, a{
    display: inline-block;
}
li{
    list-style: none;
}
a{
    text-decoration: none;
    color: #999;
}
a:hover{
    color: orange;
}
input{
    margin: 0;
    padding: 0;
    border: none;
}
/* 版心 */
.main{
    margin: 0 63.5px;
}
.fl {
    float: left;
}
.fr {
    float: right;
}
/* header start */
.header {
    width: auto;
    font-size: 12px;
}
.header .header-bar {
    height: 40px;
    background-color: #f8f8f8;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.header .header-bar .header-bar-le {
    color: #999;
}
.header .header-bar .header-bar-le a {
    margin: 0 4px;
}
.header .header-bar .header-bar-le .switch {
    border: 1px solid #e5e5e5;
    border-radius: 2px;
    color: #666;
    padding: 0 2px;
}
.header .header-bar .header-bar-le .login{
    margin-left: 15px;
    margin-right: 0;
    color: orange;
}
.header .header-bar .header-bar-le .reg {
    margin-left: 10px;
}
.header .header-bar .header-bar-ri a{
    padding: 12px 14px;
}
.header .header-content{
    height: 122px;
}
.header .header-content .header-content-title{
    padding: 28px 60px 40px 0;
} 
.header .header-content img {
    width: 126px;
    height: 46px;
}
.header .header-content .header-content-sear {
    width: 550px;
    height: 40px;
    position: absolute;
    padding-top: 28px;
    left: 50%;
    transform: translate(-50%);
}
.header .header-content .header-content-sear input{
    border: 1px solid #e5e5e5;
    border-radius: 4px 0 0 4px;
    outline: none;
    box-sizing: border-box;
    padding: 15px;
    font-size: 14px;
    width: 85.45%;
    height: 100%;
}
.header .header-content .header-content-sear button {
    width: 14.55%;
    height: 100%;
    color: #222;
    border: none;
    outline: none;
    background-color: #ffc300;
    border-bottom-right-radius: 4px;
    border-top-right-radius: 4px;
    float: right;
    box-sizing: border-box;
    cursor: pointer;
}
/* footer start */
.footer{
    width: auto;
    height: 140px;
    bottom: 0;
    background-color: #f8f8f8;
    color: #999;
    padding: 15px 0 30px 20px;
    line-height: 1.6;
    font-size: 12px;
    position: relative;
}
.footer .footer-left span {
    margin-right: 20px;
}

.footer .footer-left a {
    margin-right: 20px;
}
.footer .footer-right {
    float: right;
    text-align: right;
    position: absolute;
    top: 15px;
    right: 0;
}
.footer .footer-right .footer-right-fir {
    height: 20px;
}
.footer .footer-right .footer-right-fir img {
    width: 15px;
    height: 15px;
    vertical-align: middle;
}
.footer .footer-right .footer-right-se {
    height: 49px;
    padding: 6px 0 0;
}
.footer .footer-right .footer-right-se a:first-child{
    position: relative;
    top: -16px;
}
.footer .footer-right .footer-right-se img {
    width: 38px;
    height: 38px;
    vertical-align: middle;
}
.footer .footer-right .footer-right-se .back{
    background-image: url('./images/footer.png');
    background-repeat: no-repeat;
    height: 38px;
    margin-right: 2px;
}
.footer .footer-right .footer-right-se .img1{
    background-position: 0 -167px;
    width: 109px;    
}
.footer .footer-right .footer-right-se .img2{
    background-position: 0 -127px;
    width: 107px;
}
.footer .footer-right .footer-right-se .img3{
    background-position: 0 -40px;
    width: 107px;
}
4. 总结

  不得不说,想深刻记忆CSS和HTML必须加以练习,不然只是单纯的记住一些基础概念都是在纸上谈兵,实现上面的效果差不多花了三个多小时,虽然定位浮动什么的概念很明白,背的很溜,但是用起来总是实现不了想要的效果,不明白他们分别适用于什么场景,当然刚开始总是会有很多困难,相信自己可以克服的,再给自己加油一下!对于上面源码欢迎大家提出建议,一起讨论。