pink-移动web开发之流式布局

image-20210628223234953

改变行高只是改变上下间距的大小,

image-20210627230526776

image-20210801160059898

目标:

  1. 知道移动WEB的开发现状
  2. 写出标准的viewport
  3. 使用移动WEB的调试方法
  4. 说出移动端常见的布局方案
  5. 描述流式分布
  6. 独立完成京东移动端首页

1. 移动端基础

image-20210626203703561

image-20210626203740974

image-20210626203902759

image-20210626204023936

image-20210626204049259

image-20210626204457993

2. 视口

image-20210626204940540

image-20210626205145426

image-20210626205311520

image-20210626205501236

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />

image-20210626205946061

3. 二倍图

二倍精灵图做法

  • 先缩小一倍精灵图
  • 量logo尺寸和坐标
  • css中background-size缩小一倍 :114px auto ; (原来宽度是228)
  • 设置background-position为量出来的坐标点

image-20210626210527610

image-20210626210619510

image-20210626210727255

image-20210626210920124

image-20210626211441254

image-20210626212519951

image-20210626213150740

2014以上版本ps才能安装

4. 移动端开发选择

image-20210626213632229

image-20210626213811995

image-20210626213935576

image-20210626214018987

5. 移动端技术解决方案

image-20210626214122829

image-20210626214159148

image-20210626214508076

image-20210626215005574

6. 移动端常见布局

image-20210626215437916

流式布局

image-20210626221504445

image-20210626222221316

image-20210626222258345

image-20210626222313559

image-20210626223018367

image-20210626223213191

image-20210627001034625

image-20210627112635691

flex布局

使用flex 布局后容器和item都会变成块级元素

   <style>
        a {
            display: flex;
            text-decoration: none;
            width: 100px;
            height: 100px;
            background-color: aqua;
            justify-content: space-around;
            align-items: center;
        }
        span {
            width: 20px;
            height: 20px;
            background-color: blueviolet;
        }
    </style>
</head>
<body>
    <a href="">
        <span>1</span>
        <span>1</span>
    </a>
</body>
image-20210627131644995 image-20210627131706485

image-20210627131852503

image-20210627132154027

image-20210627132931390

image-20210627133058313

image-20210627133249964

image-20210627133305022

image-20210627135950862

image-20210627140352508

image-20210627140451094

image-20210627141001997

image-20210627141245726

image-20210627142037376

image-20210627142303126

image-20210627153457722

image-20210627154250667

image-20210627155211546

可以用百分比20%

image-20210627155357962

案例

image-20210627155542602

image-20210627155608513

image-20210627160057506

image-20210627160204482

image-20210627180622470

//二倍图
.search::before {
    content: '';
    position: absolute;
    top: 5px;
    left: 5px;
    width: 15px;
    height: 15px;
    background: url(../images/sprite.png) no-repeat -59px -279px;
    background-size: 104px auto;

rem+媒体查询适配布局

image-20210627215253967

image-20210627215335644

image-20210627225138359

image-20210627233541608

image-20210627233724640

image-20210627235059176

image-20210627235209209

image-20210628100003825

image-20210628100032024

image-20210628102811004

image-20210628103054229

 @media screen and (max-width: 539px)  {
            body {
                background-color: blue;
            }
        }
        @media screen and (min-width: 540px) and (max-width: 969px ) {//可以省略(max-width:969px)效果一样
            body {
                background-color: pink;
            }
        }
        @media screen and (min-width: 970px) {
            body {
                background-color: saddlebrown;
            }
        }

image-20210628110329812

小于用max-width,大于用min-width

image-20210628121403058

image-20210628121456105

image-20210628123335608

image-20210628123356588

image-20210628123415289

image-20210628125011390

image-20210628125111686

image-20210628125317323

image-20210628130232519

image-20210628130733664

image-20210628130830111

image-20210628130948343

image-20210628150448236

image-20210628150553932

image-20210628150627354 image-20210628152437583

image-20210628152516318

image-20210628152806901

image-20210628152902097 image-20210628152919039

image-20210628154154335

image-20210628154540073

image-20210628154550482

image-20210628154837090

image-20210628155029867

image-20210628155043661

image-20210628155237396

image-20210628155303261

1.rem+less+媒体查询

image-20210628155454352

image-20210628155656281

我们要做的效果是,在大分辨率的设备下,图片文字显示大一点,小分辨率的设备图片文字显示小一点

  • 页面中的图片、文字不能用绝对单位px写死!,rem是相对单位,相对于根元素html的font-size大小,我们可以在不同的分辨率下改变html的font-size大小就可以实现、文字图片根设备适配的效果了。
  • 那么根元素的font-size要去如何根据分辨率去改变呢?这就要用到媒体查询@media了,
  • 要实现从320分辨率的设备到750px的设备图片文字等比例缩放大小,根元素的font-size不能乱写,要按比例!
  • 例如2px的设备的font-size我们设为1,那么4px的设备的font-size我们就要设为2,320像素的设备/15份=21.33 750像素的设备就也要 / 15 = 50px,所以750px的设备font-size为50px,这样就可以实现等比例! 当然这个除的分数随便你!
  • 在一张750px的设计稿下量的div的宽度为100px,那我们应该怎么去写呢
  • 首先,等比例的不同分辨率320px和750px的font-size我们已经设好了 分别为 21.33px和50px
  • 根据设计稿,要在750像素的情况下,div要宽高为100px,
  • div的宽高要用rem做单位为了适配
  • 那么在750px的分辨率下 div的宽高要多少rem才能等于100px呢?
  • 就用750分辨率下的html的font-size来运算 100px / 50px = 2 所以div的宽高可以是 2rem
  • 在不同分辨率下,媒体查询改变对应font-size, div的宽高也等比例缩放了

image-20210628165417081

image-20210628171456722

image-20210628180046878

注意html {font-size:50px}要写在最前面,写后面会被层叠掉

pc端也可以访问移动端的网站

image-20210628181418265

image-20210628184352194

image-20210628184646274

image-20210628190127611

// 搜索模块
.search-content {
    position: fixed;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
    height: (88rem / @baseFont);
    width: 15rem;
    background-color: #FFC001;
}

2.flexible.js +rem

image-20210628224458592

image-20210628224728695

image-20210628232216384

image-20210628233819741

image-20210628234219811

image-20210628234926879

使用时,当屏幕大于750px,font-size还是会跟随屏幕来放大

image-20210629000625203

现在还是不行,还是超过750px

image-20210629000704555

样式被覆盖了

解决方法:提高权重

image-20210629001118540

响应式布局

一套页面可以适配三种设备手机、PC、ipad

image-20210630122437379

image-20210630122752003

image-20210630123505396

image-20210630153336299

image-20210630153343754

<style>
        * {
            margin: 0;
            padding: 0;
        }
        .container {
            height: 150px;
            background-color: pink;
            margin: 0 auto;
        }
        /* 超小屏幕下 小于 768 布局容器的宽度为 100% */
        @media screen and (max-width:767px ){
            .container {
                width: 100%;
            }
        }
        /* 小屏幕下 大于等于768 布局容器改为 750 px */
        @media screen and (min-width:768px) {
            .container {
                width: 750px;
            }
        }
        /* 中等屏幕 大于992px 布局容器设置为 970px */
        @media screen and (min-width:992px) {
            .container {
                width: 970px;
            }
        }
        /* 大屏幕 大于1200px 布局容器宽度设置为1170px */
        @media screen and (min-width:1200px) {
            .container {
                width: 1170px;
            }
        }
        .container ul li {
            float: left;
            width: 11.11%;
            height: 30px;
            list-style: none;
            text-align: center;
            background-color: green;
        }
        @media screen and (max-width:767px) {
            .container ul li {
                width: 33.33%;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <ul>
            <li>导航栏</li>
            <li>导航栏</li>
            <li>导航栏</li>
            <li>导航栏</li>
            <li>导航栏</li>
            <li>导航栏</li>
            <li>导航栏</li>
            <li>导航栏</li>
            <li>导航栏</li>
        </ul>
    </div>

image-20210630155151899

image-20210630155802109

image-20210630155900775

image-20210630160537495

image-20210630160650080

image-20210630161020493

image-20210630162750290

image-20210630163428708

image-20210630163929947

image-20210630164629450

image-20210630210756609

image-20210630211645894

image-20210630212010421

image-20210630213417274

image-20210630213559314

image-20210630213729102

image-20210630215900848

image-20210630222444148

image-20210630222804596

移动端布局总结

image-20210701210238992

vw vh移动端布局

image-20210701210853918

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-s4u5KZUC-1628409911062)(C:\Users\KAN\AppData\Roaming\Typora\typora-user-images\image-20210701211031565.png)]

image-20210701211313010

image-20210701212101194

image-20210701212206949

image-20210701213847986

image-20210701214304972
image-20210701214407930

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值