移动端流式布局过程——京东移动端首页案例

效果图

在这里插入图片描述


1. 准备工作

1.1 技术选型

方案: 单独制作移动页面方案
技术: 布局采取流式布局

1.2 搭建相关文件夹结构

在这里插入图片描述

1.3 设置视口标签以及引入初始化样式
    <meta name="viewport" content="width=device-width, initial-scale=1.0, 
    maximum-scale=1.0, minimum-scale=1.0,user-scalable=no">
    
    <link rel="stylesheet" href="css/normalize.css" />
    <link rel="stylesheet" href="css/index.css" />
1.4 常用初始化样式
body{
    width: 100%;
    min-width: 320px;
    max-width: 640px;
    margin: 0 auto;
    background: #fff;
    font-size: 14px;
    font-family: -apple-system, Helvetica, sans-serif;
    line-height: 1.5;
    color: #666;
}

2. 过程

2.1 body设置
  1. 宽度设置为100%,再限制一下最小宽度和最大宽度
  2. 让它们居中显示
2.2 app布局

它们是固定定位的 固定定位要设置宽度
在这里插入图片描述
京东的布局划分
在这里插入图片描述

2.2 app内容填充

在这里插入图片描述

注意:

  • 图片默认是和文字的基线对齐 (所以加个 vertical-align: middle;)图片和文字居中对齐时都加这个
2.3 搜索模块布局

在这里插入图片描述
左右两边绝对定位,中间盒子不给宽度,设置margin值

2.4 搜索模块内容制作

在这里插入图片描述
这个图片不是完全居中在盒子里的,有点偏。

在这里插入图片描述

2.5 焦点图制作

在这里插入图片描述

2.6 品牌日模块制作

竟然是把图切成三小块

在这里插入图片描述

img {
    vertical-align: middle;
}

2.7 nav模块制作

每个占20%

2.8 新闻快报模块制作

50% 25% 25%

  • n+2 就是第二2个往后面选

3. 新增知识

3.1 图片格式

DPG图片压缩技术:京东自主研发的,可直接节省用户近50%的浏览流量,提升了用户网页打开速度

webp图片格式:谷歌开发的,图片压缩体积大约只有JPEG的2/3,能节省大量的服务器宽带资源和数据空间

4. 源代码:

index.css

/* 初始化样式 */
ul{
    list-style: none;
    padding: 0;
    margin: 0;
}

/*点击高亮我们需要清除清除  设置为transparent 完成透明*/
* {
    -webkit-tap-highlight-color: transparent;
}

img {
    vertical-align: middle;
}

/*在移动端浏览器默认的外观在iOS上加上这个属性才能给按钮和输入框自定义样式*/

input {
    -webkit-appearance: none;
}


/*禁用长按页面时的弹出菜单*/

img,
a {
    -webkit-touch-callout: none;
}

a {
    color: #666;
    text-decoration: none;
}


.clearfix:after {
    content: "";
    display: block;
    line-height: 0;
    visibility: hidden;
    height: 0;
    clear: both;
}

body{
    width: 100%;
    min-width: 320px;
    max-width: 640px;
    margin: 0 auto;
    background: #fff ;
    font-size: 14px;
    font-family: -apple-system, Helvetica, sans-serif;
    line-height: 1.5;
    color: #666;
}

.app{
    height: 45px;
}


.app ul li {
    float: left;
    height: 45px;
    line-height: 45px;
    background-color: #333333;
    text-align: center;
    color: #fff;
}

.app ul li:nth-child(1){
    width: 8%;
}

.app ul li:nth-child(1) img{
    width: 10px;
}

.app ul li:nth-child(2){
    width: 10%;
}

.app ul li:nth-child(2) img{
    width: 30px;
    vertical-align: middle;
}

.app ul li:nth-child(3){
    width:57%;
}

.app ul li:nth-child(4) {
    width: 25%;
    background-color: #F63515;
}

/* 搜索 */

.search-wrap{
    position: fixed;
    width: 100%;
    min-width: 320px;
    max-width: 640px;
    height: 44px;
    overflow: hidden;
}

.search-btn{
    position: absolute;
    top: 0;
    left: 0;
    width: 40px;
    height: 44px;
}

.search-btn::before{
    content: "";
    display: block;
    width: 20px;
    height: 18px;
    background: url(../images/s-btn.png) ;
    background-size: 20px  18px;
    margin: 14px 0 0 15px;
}
.search-login{
    position: absolute;
    top: 0;
    right: 0;
    width: 40px;
    height: 44px;
    text-align: center;
    line-height: 44px;
    color: #fff;
}

.search{
    position: relative;
    height: 32px;
    background-color: #fff;
    margin: 0 50px;
    border-radius: 15px;
    margin-top: 7px;
}

.jd-icons{
    width: 20px;
    height: 15px;
    position: absolute;
    top: 8px;
    left: 11px;
    background: url(../images/jd.png) no-repeat;
    background-size: 20px 15px;
}

.jd-icons::after {
    content: "";
    position: absolute;
    right: -7px;
    top: 0;
    display: block;
    width: 1px;
    height: 15px;
    background-color: #ccc;
}

.sou{
    position: absolute;
    top: 8px;
    left: 50px;
    width: 18px;
    height: 15px;
    background: url(../images/jd-sprites.png) no-repeat -81px 0;
    background-size: 200px auto;
}
/* 滑动图 */

.slider img{
    width: 100%;
}

.brand div {
    float: left;
    width: 33.33%;
}

.brand div img {
    width: 100%;
}

/* nav */

nav {
    padding-top: 5px;
}

nav a {
    float: left;
    width: 20%;
    text-align: center;
}

nav a img {
    width: 40px;
    margin: 10px 0;
}

nav a span {
    display: block;
}

/* news */

.news {
    margin-top: 20px;
}

.news img {
    width: 100%;
}

.news a {
    float: left;
    box-sizing: border-box;
}

.news a:nth-child(1) {
    width: 50%;
}

.news a:nth-child(n+2) {
    width: 25%;
    border-left: 1px solid #ccc;
}

html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, 
    maximum-scale=1.0, minimum-scale=1.0,user-scalable=no">
    <title>Document</title>
    <link rel="stylesheet" href="css/normalize.css" />
    <link rel="stylesheet" href="css/index.css" />
</head>
<body>
    <div class="app">
        <ul>
            <li class="app-items">
                <img src="./images/close.png" alt="">
            </li>
            <li class="app-items">
                <img src="./images/logo.png" alt="">
            </li>
            <li class="app-items">打开京东App,购物更轻松</li>
            <li class="app-items">立即打开</li>
        </ul>
    </div>

    <!-- 搜索 -->
    <div class="search-wrap">
        <div class="search-btn"></div>
        <div class="search">
            <div class="jd-icons"></div>
            <div class="sou"></div>
        </div>
        <div class="search-login">登陆</div>
    </div>

    <!-- 主体内容部分 -->
    <div class="main-content">
        <!-- 滑动图 -->
        <div class="slider">
            <img src="upload/banner.dpg" alt="">
        </div>

        <!-- 小家电品牌日 -->
        <div class="brand">
            <div>
                <a href="#">
                    <img src="upload/pic11.dpg" alt="">
                </a>
            </div>
            <div>
                <a href="#">
                    <img src="upload/pic22.dpg" alt="">
                </a>

            </div>
            <div>
                <a href="#">
                    <img src="upload/pic33.dpg" alt="">
                </a>

            </div>
        </div>

        <!-- nav部分 -->
        <nav class="clearfix">
            <a href="">
                <img src="upload/nav1.webp" alt="">
                <span>京东超市</span>
            </a>

            <a href="">
                <img src="upload/nav2.webp" alt="">
                <span>京东超市</span>
            </a>

            <a href="">
                <img src="upload/nav3.webp" alt="">
                <span>京东超市</span>
            </a>

            <a href="">
                <img src="upload/nav2.webp" alt="">
                <span>京东超市</span>
            </a>

            <a href="">
                <img src="upload/nav1.webp" alt="">
                <span>京东超市</span>
            </a>

            <a href="">
                <img src="upload/nav2.webp" alt="">
                <span>京东超市</span>
            </a>

            <a href="">
                <img src="upload/nav3.webp" alt="">
                <span>京东超市</span>
            </a>

            <a href="">
                <img src="upload/nav2.webp" alt="">
                <span>京东超市</span>
            </a>

            <a href="">
                <img src="upload/nav1.webp" alt="">
                <span>京东超市</span>
            </a>

            <a href="">
                <img src="upload/nav2.webp" alt="">
                <span>京东超市</span>
            </a>

        </nav>

                <!-- 新闻模块 -->
                <div class="news">
                    <a href="#">
                        <img src="upload/new1.dpg" alt="">
                    </a>
                    <a href="#">
                        <img src="upload/new2.dpg" alt="">
        
                    </a>
                    <a href="#">
                        <img src="upload/new3.dpg" alt="">
        
                    </a>
                </div>
    </div>
</body>
</html>
  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值