移动端布局--适配

1、移动端布局方式

  • 百分比(%)
  • 弹性盒布局
  • rem布局        

2、弹性盒子(display-flex)

        影响:
                1.子元素默认横向排列

                2.行内元素,转换成块级元素

                3.只有一个子元素,在子元素添加margin:auto,子元素水平垂直居中。                

属性用法属性值
flex-direction修改主轴方向

row (水平排列)

column(竖直排列)

justify-content调整主轴对齐方式flex-start(左对齐)
flex-end (右对齐)
center (居中)
space-between (两端对齐)
space-around (距离环绕)
align-items调整侧轴flex-start(左对齐)
flex-end (右对齐)
center (居中)
space-between (两端对齐)
space-around (距离环绕)
flex-warp换行warp (换行)
align-content控制 换行后行间距flex-start(左对齐)
flex-end (右对齐)
center (居中)
space-between (两端对齐)
space-around (距离环绕)
align-self项目-对齐方式flex-start(上对齐)
flex-end (下对齐)
center (居中)
stretch(拉伸充满)
order项目-调整顺序数值(值越大,越靠后)
flex项目-剩余宽高数值(撑满剩余部分)
flex-shrink值为1时,表示所有子元素同时按比例压缩值为0时,表示不缩小适应(结合:overflow:auto使用)

3、模拟器上显示分辨率

        css像素:设备的独立像素

        物理分辨率:设备像素

        设备像素比(dpr) = 物理像素/css像素

4、meta标签

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

      用户不允许双击缩放:  user-scalable=no

5、移动端布局-案例(原生)

<body>
    <header>
        <div>热点</div>
        <div>关注</div>
    </header>
    <section>
        <ul>
            <li>足球现场</li>
            <li>足球生活</li>
            <li>足球美女</li>
        </ul>
        <div class="list">
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
        </div>
    </section>
    <footer>
        <ul>
            <li>首页</li>
            <li>发现</li>
            <li class="camera">
                <span>相机</span>
            </li>
            <li>我的</li>
            <li>退出</li>
        </ul>
    </footer>
</body>

    <style>
        * {
            margin: 0;
            padding: 0;
        }
        ul {
            list-style: none;
        }
        html,
        body {
            height: 100%;
        }
        body {
            display: flex;
            flex-direction: column;
        }
        header {
            height: 44px;
            background-color: #0ac13b;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 14px;

        }
        header div {
            width: 61px;
            height: 25px;
            line-height: 25px;
            text-align: center;
        }
        header div:nth-child(1) {
            border-radius: 15px 0 0 15px;
            background-color: #64d687;
            color: #f0fefa;

        }
        header div:nth-child(2) {
            border-radius: 0 15px 15px 0;
            background-color: #3ecf67;
            color: #9cebae;
        }
        section {
            flex: 1;
            overflow-y: auto;
        }
        section ul {
            display: flex;
            position: sticky;  /*粘性定位*/
            top: 0;
            background-color: #fff;
        }
        section ul li {
            line-height: 44px;
            text-align: center;
            flex: 1;
            border-bottom: 1px solid #ccc;
        }
        section ul li:hover {
            color: springgreen;
            border-bottom: 2px solid springgreen;
        }
        section .list {
            display: flex;
            justify-content: space-between;
            flex-wrap: wrap;
            margin-bottom: 2px;
        }
        section .list div {
            margin-top: 2px;
            width: 49%;
            height: 200px;
            border: 1px solid pink;
        }
        footer {
            height: 40px;
        }

        footer ul {
            display: flex;
        }
        footer ul li {
            flex: 1;
            text-align: center;
            line-height: 40px;
            font-size: 14px;
            border-top: 1px solid #ccc;
        }
        footer ul .camera {
            flex: 1;
            position: relative;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        footer ul .camera span {
            position: absolute;
            top: -13px;
            width: 50px;
            height: 50px;
            line-height: 50px;
            border: 1px solid #ccc;
            border-radius: 50%;
            background-color: #fff;
        }
        footer ul li:hover {
            color: springgreen;
        }
    </style>

6、多列布局(瀑布流效果)

属性用法属性值
column-count显示的列数数值
column-gap调整列间距px
column-rule列边框2px solid #ff6600
column-fill列高度统一balance/auto(把父盒子占满)
column-span(设置在子元素)横跨所有列none/all(横跨所有列)
break-inside禁止盒子内部折行avoid

7、响应式布局-媒体查询

/*pc客户端或大屏幕设备:1028px至最大*/
@media only screen and (min-width:1029px){对应样式}

/*竖屏*/
@media screen and(orientation:portrait) and (min-width:720px){对应样式}

/*横屏*/
@media screen and (orientation:landscape){对应样式}

设备类型:screen (显示器、笔记本、移动端等设备)、all (全部)

关键字:and 、not(排除某种设备)、only(限定某种设备)

媒体特性:(min-width:1029px)

8、em 与 rem

  • em:相对单位,相对于父元素的字体大小
  • rem:相对单位,相对于根元素(html)字体大小
html{
    font-size:100px; //基准
}
body{
    font-size:16px
}

// font-size 计算
document.documentElement.style.fontSize = document.documentElement.clientWidth/750*100+'px'

// fontSize = 当前设备的css布局宽度/物理分辨率(设计稿的宽度)*基准font-size
// rem ==== 等比例缩放布局

 9、vh 与 vw

  • vh:view-hright    100vh === 视口高度
  • vw:view-width    100vw === 视口宽度

 100vw  包含滚动条,窗口大小

 100%   刨除滚动条,剩余的空间占满

375px  =  100vw

1px = 100/375 vw  0.2667

    <style>
        *{
            margin: 0;
            padding: 0;
        }
        html{
            font-size: 26.67vw;  //vw
        }
  
        .box1{
            font-size: 0.16rem;
            height: 100px;
            background-color: pink;
        }
        .box2{
            font-size: 16px;
        }
    </style>

10、音频-案例 (基于vue+vant组件库)

        <div class="audio-order v-flex">  //v-flex —— display:flex
          <div class="audio-title">
            <div>
              <van-icon
                class="v-m-r-4"    //v-m-r-4 —— margin-right:0.04rem
                name="volume-o"
                size="0.12rem"
              />睡前放松练习
            </div>
            <div class="audio-time">
              {{ audioCurrentTime }} /{{ audioAllTime }}
            </div>
          </div>
          <div>
            <van-icon
              v-if="audioPlayShow"
              @click="audioPlayBtn"
              name="play-circle-o"
              size="0.22rem"
            />
            <van-icon
              v-if="audioPauseShow"
              @click="audioPauseBtn"
              name="pause-circle-o"
              size="0.22rem"
            />
          </div>
          <audio
            ref="audio"
            src="https://h5.jxr-fertility.com/28days_01.mp3"
            @timeupdate="getCurr"
            @loadedmetadata="getTime"
          ></audio>
        </div>
// 时间转为秒
export const getS = (sec) => {
    let s = sec % 60 < 10 ? ('0' + sec % 60) : sec % 60
    let min = Math.floor(sec / 60) < 10 ? ('0' + Math.floor(sec / 60)) : Math.floor(sec / 60)
    return min + ':' + s
}

import { getS } from "@/utils/tools";
export default {
  data() {
    return {
      audioPlayShow: true, //播放按钮
      audioPauseShow: false, //暂停按钮
      audioCurrentTime: "00:00", //音频当前播放时间
      audioAllTime: "00:00", //音频总播放时间
    };
  },
  methods: {
    // 播放
    audioPlayBtn() {
      this.$refs.audio.play();
      this.audioPlayShow = false;
      this.audioPauseShow = true;
    },
    // 暂停
    audioPauseBtn() {
      this.$refs.audio.pause();
      this.audioPlayShow = true;
      this.audioPauseShow = false;
    },
     //音频当前播放时间
    getCurr() {
      this.audioCurrentTime = getS(parseInt(this.$refs.audio.currentTime));
    },
     //音频总播放时间
    getTime() {
      this.audioAllTime = getS(parseInt(this.$refs.audio.duration));
    },
  },
};
  .audio-order
    box-sizing: border-box
    background-color: rgba(182, 162, 232, 0.9)
    color: #fff
    margin-bottom: 0.3rem
    padding: 0.1rem
    border-radius: 0.1rem
    font-size: 0.12rem
    .audio-time
      margin-top: 0.05rem

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值