移动端复习

移动端复习

rem 实际开发适配方案

移动端的适配方案一般是根据设计稿来实现的,假设设计稿是750px,项目使用normalize.css来清除默认的样式,使用flexible.js来检测屏幕,将屏幕划分为10等分,在VScode使用插件px to rem & rpx & vw (cssrem),首先设置好设计稿的的尺寸除以10作为插件的默认字体大小,方便后续的计算

实例

新建文件夹,在文件夹下创建images用于保存图片,js用于保存js文件,css用于保存样式,新建一个ndex.html

页面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="./css/normalize.css">
  <script src="./js/index.js"></script>
  <link rel="stylesheet" href="./css/index.css">
</head>
<body>
  <div class="container">
    <div class="right">
      <img src="./images/分类.png" alt="">
      <span>分类</span>
    </div>
    <div class="myInput">
      <input type="search" placeholder="请输入你想要的内容">
    </div>
    <div class="left">
      <img src="./images/my.png" alt="">
      <span>我的</span>
    </div>
  </div>
</body>
</html>

css的样式为:

@media screen and (min-width:750px) {
  html {
    font-size: 75px !important;
  }
}
.container {
  width: 10rem;
  height: 1rem;
  background-color: red;
  margin: 0 auto;
  display: flex;
  align-items: center;
}
a {
  text-decoration: none;
}
span {
  color: rgba(255, 241, 116, 0.64);
}
.right,
.left {
  width: 1.0667rem;
  height: 1rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  font-size: .1867rem;
}
.right img,
.left img {
  width: .4rem;
  margin-bottom: .1067rem;
}
.left {
  padding-right: .2rem;
}
.right {
  padding-left: .2rem;
}
.myInput {
  width: 100%;
  height: 1rem;
  text-align: center;
}
.myInput input {
  width: 90%;
  height: .8rem;
  outline: none;
  border: none;
  border-radius: .6rem;
  margin-top: .0933rem;
  padding: 0 .4rem;
  color: #333;
  font-size: .1867rem;
}

打开浏览器就可以查看到在设计稿750px以下的部分不会发生变化,随着屏幕的缩小,导航栏也会随着缩小。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值