移动端三种布局方式之rem布局-苏宁首页(技术方案二:flexible.js 、rem)

结果图

在这里插入图片描述
 
 

准备工作

 
 

  1. 建立文件夹在这里插入图片描述
     
     
  2. 引入文件
<!-- 引入移动端初始化文件 -->
    <link rel="stylesheet" href="css/normalize.css">
    <!-- 引入主页的css文件 -->
    <link rel="stylesheet" href="css/index.css">
    <!-- 引入js文件 -->
    <script src="js/flexible.js" ></script>

 
 
3. body初始化

body {
    min-width: 320px;
    max-width: 750px;
    /* flexible 根据当前屏幕给我们划分了 10 等份 ,所以要设置最大宽度*/
    /* 750/(750/10) */
    width: 10rem;
    margin: 0 auto;
    line-height: 1.5;
    font-family: Arial, Helvetica;
    background: #f2f2f2;
}

 
 
4. 检查
屏幕大小1392px在这里插入图片描述
iphone8 375px
在这里插入图片描述

检查有没有划分成10等份,在浏览器和手机端 html文字大小为当前页面大小/划分份数
 
 
5. cssrem插件
cssrem一个自动把px转化成rem的插件,不需要less那么麻烦
这个插件默认的文字大小是cssroot 16px
修改默认字体大小方法
在这里插入图片描述

在这里插入图片描述
75是html文字大小,稿件750px/划分份数
 
 

代码

css

body {
    min-width: 320px;
    max-width: 750px;
    /* flexible 根据当前屏幕给我们划分了 10 等份 ,所以要设置最大宽度*/
    /* 750/(750/10) */
    width: 10rem;
    margin: 0 auto;
    line-height: 1.5;
    font-family: Arial, Helvetica;
    background: #f2f2f2;
}
a {
    text-decoration: none;
    font-size: .333333rem;
}
/* 如果屏幕超过了750px那么我们就按照750的设计稿件走,不会让屏幕超过750px,超过750px也按750px的稿件来走 */
@media screen and(min-width:750px) {
    html{
        /* !important提高权重,执行这条代码而不是给我们的原始屏幕的字体大小 */
        font-size: 75px!important;
    }
}

/* cssrem一个自动把px转化成rem的插件,不需要less那么麻烦 */
/* 这个插件默认的文字大小是cssroot 16px */
.search-content{
    display: flex;
    position: fixed;
    top: 0;
    left: 50%;
    transform: translate(-50%);
    width: 10rem;
    height: 1.173333rem;
    background-color: #ffc001;

}
.classify {
    width: .586667rem;
    height: .933333rem;
    margin: .146667rem .333333rem .133333rem;
    background: url(../images/classify.png) no-repeat;
    /* 缩放背景图 */
    background-size: .586667rem .933333rem;
}
.search{
    flex: 1;
}
.search input {
    outline: none;
    border: 0;
    width: 100%;
    height: .88rem;
    font-size: .333333rem;
    background-color: #FFF2CC;
    margin-top: .133333rem;
    border-radius: .44rem;
    color: #757575;
    padding-left: .733333rem;
}
.login {
    width: 1rem;
    height: .933333rem;
    margin: .133333rem;
    color: #fff;
    text-align: center;
    line-height: .933333rem;
    font-size: .333333rem;
}

 
 

html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=no,maximum-scale=1.0,minimum-scale=1.0">
    
    <!-- 引入移动端初始化文件 -->
    <link rel="stylesheet" href="css/normalize.css">
    <!-- 引入主页的css文件 -->
    <link rel="stylesheet" href="css/index.css">
    <!-- 引入js文件 -->
    <script src="js/flexible.js" ></script>
    <title>Document</title>
</head>
<body>
    <div class="search-content">
        <a href="#" class="classify"></a>
        <div class="search">
            <form action="">
                <input type="search" value="rem适配方案2很开心哦">
            </form>
        </div>
        <a href="#" class="login">登录</a>
    </div>
</body>

</html>
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值