案例八---足球圈移动端布局

本文探讨了移动端布局在足球圈应用中的实现,重点介绍了设备像素、设计稿标准及百分比、弹性盒布局和REM布局的使用。通过具体案例代码,展示了如何处理宽度、高度的计算,以及在弹性盒中实现元素的居中和定位。同时,提到了meta标签的配置,以及在开发过程中需要注意的细节问题,如伪类选择器和定位的运用。

一:移动端布局

1:在网页模拟器上显示的分辨率为CSS像素:设备的独立像素

2:物理分辨率为设备的实际像素。

3:设备像素比(dpr)=物理像素/CSS像素;

4:设计稿:a:是按照物理像素设计

                    b:多个设备一份设计稿

                    c:尽量使用百分比布局

                    d:弹性盒布局 / rem布局

5:meta标签,必须要加,一般默认工程都会加

还可添加属性:user-scalable=no;不允许用户放大页面

 6:

二:案例代码

<!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>Document</title>
    <!-- 引入特殊符号字体文件 -->
    <link rel="stylesheet" href="./history/material/font_3724085_b2nkdmmbdqh/iconfont.css">
    <!-- CSS部分 -->
    <style>
        /* 以下为必写内容 */
        *{
            margin: 0;
            padding: 0;
        }
        ul{
            list-style: none;
        }
        html,body{
            height: 100%;
        }
        /* ********** */
        /* 高度值=量取的值/2,固定的宽度值也同理*/
        body{
            display: flex;
            flex-direction: column;
        }

        /* herader部分 */
        header{
            height: 44px; /* 量取值大约为88 */
            background: #0cc440;
            display: flex;
            /* ****** */
            justify-content: center;/*  */
            align-items: center;/* flex子项垂直居中  */
            /* ****** */
        }

        header div{
            width: 60px;
            height: 25px;
            line-height: 25px;
            text-align: center;
            font-size: 12px;
        }

        header div:nth-child(1){/* 指定header中第一个div */
            /* 设置左上角,左下角的圆角 */
            border-radius: 12px 0 0 12px;
            background: #63d985;
            color: white;/* 设置字体颜色 */
        }

        header div:nth-child(2){/* 同上,指定header中第二个div */
            /* 设置右上角,右下角的圆角 */
            border-radius: 0 12px 12px 0;
            background: #3dd066;
            color: #a9e4b4;
        }

        /* section部分  导航栏 */
        section{
            flex: 1;
            overflow: auto;/* 不设置此处,会挤压header以及footer显示空间,导致footer无法正常显示
                              内容溢出,会出现滚动条 */
        }

        section ul{ /* 要清楚哪个是要设置为flex的盒子,哪个是子项 */
            display: flex;
            position: sticky;/* 黏性定位,让导航栏保留在上面,滑动滚动条,导航栏位置不变 */
            top: 0px;
            background: white;
        }

        section ul li{
            flex: 1;
            text-align: center;
            height: 35px;
            line-height: 35px;
            border-bottom: 1px solid #d9d9d9;
            color: #8c8c8c;
            font-size: 14px;
        }

        section ul li:hover{ /* 鼠标移到此处,字体以及边框底部会改变颜色和高度 */
            border-bottom: 2px solid #08c93e;
            color: #14bf4d;
        }

        /* section部分  内容部分 */

        section .list{
            display: flex;
            flex-wrap: wrap;/* 折行 */
            justify-content: space-between;/* 两端对齐 */
        }

        section .list>div{
            width: 49%; /* ****** */
            margin-top: 4px;
            border: 1px solid #8c8c8c;
        }

        section .list>div img{
            width: 100%; /* 设置图片宽度等于父盒子的宽度 */
        }

        section .list>div p{
            height: 30px;
            line-height: 30px;
            font-size: 12px;
            text-indent: 10px;/* 设置文本块的首行缩进 */
        }

        /* footer部分 */
        footer{
            height: 44px;
            background: white;
            color: #d5d5d7;
        }

        footer ul{
            display: flex;
            height: 100%;/* *** */
        }

        footer li{
            height: 100%;/* *** */
            flex: 1;
            display: flex;
            flex-direction: column;
            justify-content: center;
        }

        footer li:hover{
            color: #08ca43;
        }
        
        footer li i{
            height: 21px;
            font-size: 16px;
            line-height: 21px;
            text-align: center;
        }

        footer li span{
            height: 17px;
            font-size: 12px;
            line-height: 17px;
            text-align: center;
        }

        footer li:nth-child(3){
            position: relative; /* *** */
        }

        footer li:nth-child(3) i{
            width: 50px;
            height: 50px;
            border: 1px solid #dadada;
            border-radius: 50%;
            position: absolute; /* 不再受弹性盒影响 */
            left: 50%;
            margin-left: -25px;
            top: -8px;
            font-size: 30px;
            /* 设置水平,垂直居中 */
            text-align: center;
            line-height: 50px;
            background: white;
        }

    </style>
</head>
<body>

    <header>
        <div>热点</div>
        <div>关注</div>
    </header>
    <section>
        <!-- 导航栏部分 -->
        <ul>
            <li>足球现场</li>
            <li>足球生活</li>
            <li>足球宝贝</li>
        </ul>

        <!-- 内容部分 -->
        <div class="list">
            <div>
                <img src="/history/photo/足球圈.png" alt="">
                <p>可可爱爱小丸子</p>
            </div>
            <div>
                <img src="/history/photo/足球圈.png" alt="">
                <p>可可爱爱小丸子</p>
            </div>
            <div>
                <img src="/history/photo/足球圈.png" alt="">
                <p>可可爱爱小丸子</p>
            </div>
            <div>
                <img src="/history/photo/足球圈.png" alt="">
                <p>可可爱爱小丸子</p>
            </div>
            <div>
                <img src="/history/photo/足球圈.png" alt="">
                <p>可可爱爱小丸子</p>
            </div>
            <div>
                <img src="/history/photo/足球圈.png" alt="">
                <p>可可爱爱小丸子</p>
            </div>
        </div>
    </section>
    <footer>
        <ul>
            <li>
                <i class="iconfont icon-banquan"></i>
                <span>首页</span>
            </li>
            <li>
                <i class="iconfont icon-banquan"></i>
                <span>发现</span>
            </li>
            <li>
                <i class="iconfont icon-chayan"></i>
            </li>
            <li>
                <i class="iconfont icon-banquan"></i>
                <span>我的</span>
            </li>
            <li>
                <i class="iconfont icon-banquan"></i>
                <span>退出</span>
            </li>
        </ul>
    </footer>
</body>
</html>

三:运行效果

四:注意点

1:在量取高度或者宽度值得时候,除了宽度设置百分比之外,其他量取的值均除以2。

2:在写弹性盒的时候,要分清哪个是父项,哪个是子项,别设置错了

3:熟悉弹性盒中如何子项设置垂直,水平居中

4:熟练应用案例footer部分弹性盒的应用

5:熟悉一些伪类选择器的应用

例如案例中使用的:header div:nth-child(1){}等

6:熟练掌握footer部分中间放大图像的设置,使用绝对定位position可以让此不再受弹性盒的限制

父盒子:position: relative;

子盒子:position: absolute;

7:height: 100%; 的应用

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值