当前位置: 首页 > news >正文

使用Flexible实现手淘H5页面的终端适配的注意事项

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

具体思路,请参考大漠的原文,此处仅提供部分源码注意事项。

html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="yes" name="apple-touch-fullscreen">
    <meta content="telephone=no,email=no" name="format-detection">
    <script src="./javascript/flexible_css.debug.js"></script>
    <script src="./javascript/flexible.debug.js"></script>
    <title>再来一波DEMO</title>
    <link rel="stylesheet" href="../dist/tmall_goods.css"/>
</head>
<body>
<div>
    <div>
        <h2><img src="http://gw.alicdn.com/mt/TB1PNLZKXXXXXaTXXXXXXXXXXXX-750-481.jpg" alt=""></h2>
    </div>
    <ul>
        <li>
            <a class="list-item goods"><img src="https://placeimg.com/350/350/people/grayscale" alt=""></a>
            <div class="list-item goods-details">
                <p>Carter's1年式灰色长袖连体衣包脚爬服全棉鲸鱼男婴儿童装115G093</p>
                <div>
                    <span>双11价</span>
                    <strong>¥299.06</strong>
                    <small>(满400减100)</small>
                </div>
                <p>1小时内热卖5885件</p>
                <a href="javascript:void(0);">马上抢!</a>
            </div>
        </li>
        <li>
            <a class="list-item goods"><img src="https://placeimg.com/350/350/people/grayscale" alt=""></a>
            <div class="list-item goods-details">
                <p>Carter's1年式灰色长袖连体衣包脚爬服全棉鲸鱼男婴儿童装115G093</p>
                <div>
                    <span>双11价</span>
                    <strong>¥299.06</strong>
                    <small>(满400减100)</small>
                </div>
                <p>1小时内热卖5885件</p>
                <a href="javascript:void(0);">马上抢!</a>
            </div>
        </li>
    </ul>
</div>
</body>
</html>

src中的tmall_goods.css

html,body{height: 100vh;}
.g-warp{min-height:100%;background-color: #ee0a3b;position:relative;font-size:12px;/*px*/}
.g-header{text-align:center}
.g-header img{width:750px}
.goods-lists{padding:10px}
.goods-lists .list{display:table;width:100%;margin-bottom:1px;background-color:#fff}
.goods-lists .list-item{display:table-cell;padding:10px 0;vertical-align:top;background-color:#fff}
.goods-lists .goods{width:130px;height:130px;/*px*/}
.goods-lists .goods img{width:130px;height:130px;/*px*/vertical-align:top}

.goods-lists .goods-details{width:2700px;padding-left:10px;padding-right:10px;position:relative}
.goods-lists .goods-title{color:#333;line-height:1.25;overflow:hidden;-webkit-line-clamp:2;line-clamp:2;-webkit-box-orient:vertical;box-orient:vertical;display:-webkit-box;display:box}
.goods-lists .describe-wrap{padding: 10px 0 6px}
.goods-lists .goods-tag{display:inline-block;background-color:#ee0a3b;vertical-align:middle;border-radius:4px;padding:4px 2px;color:#fff;font-weight:700;margin-right:4px;font-size:12px;/*px*/}
.goods-lists .goods-price{display:inline-block;vertical-align:middle;font-weight:700;color:#ee0a3b;font-size:16px;/*px*/margin-right:10px}
.goods-lists .goods-des{display:inline-block;vertical-align:middle;font-weight:700;color:#ee0a3b;font-size:12px;/*px*/}
.goods-lists .goods-sold{color:#ff3600}
.goods-lists .btn{position:absolute;width:116px;height:34px;line-height:34px;background-color:#ee0a3b;text-align:center;color:#fff;font-weight:700;font-size:14px;/*px*/bottom:10px;right:20px;border-radius:4px}

处理后dist中的tmall_goods.css

html,
body {
  height: 100vh;
}

.g-warp {
  min-height: 100%;
  background-color: #ee0a3b;
  position: relative;
}

[data-dpr="1"] .g-warp {
  font-size: 6px;
}

[data-dpr="2"] .g-warp {
  font-size: 12px;
}

[data-dpr="3"] .g-warp {
  font-size: 18px;
}

.g-header {
  text-align: center;
}

.g-header img {
  width: 10rem;
}

.goods-lists {
  padding: 0.133333rem;
}

.goods-lists .list {
  display: table;
  width: 100%;
  margin-bottom: 0.013333rem;
  background-color: #fff;
}

.goods-lists .list-item {
  display: table-cell;
  padding: 0.133333rem 0;
  vertical-align: top;
  background-color: #fff;
}

.goods-lists .goods {
  width: 1.733333rem;
}

[data-dpr="1"] .goods-lists .goods {
  height: 65px;
}

[data-dpr="2"] .goods-lists .goods {
  height: 130px;
}

[data-dpr="3"] .goods-lists .goods {
  height: 195px;
}

.goods-lists .goods img {
  width: 1.733333rem;
  vertical-align: top;
}

[data-dpr="1"] .goods-lists .goods img {
  height: 65px;
}

[data-dpr="2"] .goods-lists .goods img {
  height: 130px;
}

[data-dpr="3"] .goods-lists .goods img {
  height: 195px;
}

.goods-lists .goods-details {
  width: 36rem;
  padding-left: 0.133333rem;
  padding-right: 0.133333rem;
  position: relative;
}

.goods-lists .goods-title {
  color: #333;
  line-height: 1.25;
  overflow: hidden;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  box-orient: vertical;
  display: -webkit-box;
  display: box;
}

.goods-lists .describe-wrap {
  padding: 0.133333rem 0 0.08rem;
}

.goods-lists .goods-tag {
  display: inline-block;
  background-color: #ee0a3b;
  vertical-align: middle;
  border-radius: 0.053333rem;
  padding: 0.053333rem 0.026667rem;
  color: #fff;
  font-weight: 700;
  margin-right: 0.053333rem;
}

[data-dpr="1"] .goods-lists .goods-tag {
  font-size: 6px;
}

[data-dpr="2"] .goods-lists .goods-tag {
  font-size: 12px;
}

[data-dpr="3"] .goods-lists .goods-tag {
  font-size: 18px;
}

.goods-lists .goods-price {
  display: inline-block;
  vertical-align: middle;
  font-weight: 700;
  color: #ee0a3b;
  margin-right: 0.133333rem;
}

[data-dpr="1"] .goods-lists .goods-price {
  font-size: 8px;
}

[data-dpr="2"] .goods-lists .goods-price {
  font-size: 16px;
}

[data-dpr="3"] .goods-lists .goods-price {
  font-size: 24px;
}

.goods-lists .goods-des {
  display: inline-block;
  vertical-align: middle;
  font-weight: 700;
  color: #ee0a3b;
}

[data-dpr="1"] .goods-lists .goods-des {
  font-size: 6px;
}

[data-dpr="2"] .goods-lists .goods-des {
  font-size: 12px;
}

[data-dpr="3"] .goods-lists .goods-des {
  font-size: 18px;
}

.goods-lists .goods-sold {
  color: #ff3600;
}

.goods-lists .btn {
  position: absolute;
  width: 1.546667rem;
  height: 0.453333rem;
  line-height: 0.453333rem;
  background-color: #ee0a3b;
  text-align: center;
  color: #fff;
  font-weight: 700;
  bottom: 0.133333rem;
  right: 0.266667rem;
  border-radius: 0.053333rem;
}

[data-dpr="1"] .goods-lists .btn {
  font-size: 7px;
}

[data-dpr="2"] .goods-lists .btn {
  font-size: 14px;
}

[data-dpr="3"] .goods-lists .btn {
  font-size: 21px;
}

gulp和gulp插件 gulpfile.js

var gulp = require('gulp');

var postcss = require('gulp-postcss');

var px2rem = require('postcss-px2rem');


gulp.task('default', function() {

    var processors = [px2rem({remUnit: 75})];

    return gulp.src('./src/css/tmall_goods.css')

        .pipe(postcss(processors))

        .pipe(gulp.dest('./dist'));

});

使用postcss-px2rem插件处理px时候,需要在使用时候注意每个属性后面的分号不能省略,默认是都转换为rem,如若某个属性不需要转换为rem,需要按照dpr不同而分别设置大小,则在后面加上注释/*px*/,如若需要原样输出,则在后面加上注释/*no*/,此处需要多加留意,对于刚接触的我们新手来说,是个坑啊!


转载于:https://my.oschina.net/wbo0801/blog/618469

相关文章:

  • Installing and Using Standby Statspack in 11g
  • 美国:《网络安全国家行动计划》(2016年2月)
  • CentOS 目录结构
  • php7安装笔记,个人零时笔记
  • ioS开发知识(二十八)
  • 单例模式里面必须要知道的事情
  • 保留两位小数
  • Spring-boot 启动时碰到的错误
  • 开源监控解决方案Nagios+Cacti+PNP4Nagios+NConf+NDOUtils+Nagvis(三)pnp4nagios安装
  • 利用Python进行文章特征提取(二)
  • 点击推送消息跳转处理(iOS)
  • 2.C#中泛型在方法Method上的实现
  • 简单的苗为课堂搜索版式编写《超链接》
  • 深入字节码 -- 计算方法执行时间
  • Building QT projects from the command line
  • 10个最佳ES6特性 ES7与ES8的特性
  • Android开源项目规范总结
  • hadoop入门学习教程--DKHadoop完整安装步骤
  • jdbc就是这么简单
  • jquery cookie
  • laravel 用artisan创建自己的模板
  • mysql_config not found
  • PHP CLI应用的调试原理
  • SpiderData 2019年2月23日 DApp数据排行榜
  • 从地狱到天堂,Node 回调向 async/await 转变
  • 聊聊sentinel的DegradeSlot
  • 前端 CSS : 5# 纯 CSS 实现24小时超市
  • 如何编写一个可升级的智能合约
  • 使用putty远程连接linux
  • 使用阿里云发布分布式网站,开发时候应该注意什么?
  • 数据仓库的几种建模方法
  • UI设计初学者应该如何入门?
  • 曾刷新两项世界纪录,腾讯优图人脸检测算法 DSFD 正式开源 ...
  • $(document).ready(function(){}), $().ready(function(){})和$(function(){})三者区别
  • (2)MFC+openGL单文档框架glFrame
  • (9)YOLO-Pose:使用对象关键点相似性损失增强多人姿态估计的增强版YOLO
  • (pt可视化)利用torch的make_grid进行张量可视化
  • (阿里巴巴 dubbo,有数据库,可执行 )dubbo zookeeper spring demo
  • (二)换源+apt-get基础配置+搜狗拼音
  • (附源码)计算机毕业设计SSM疫情居家隔离服务系统
  • (力扣)1314.矩阵区域和
  • (三)模仿学习-Action数据的模仿
  • (轉)JSON.stringify 语法实例讲解
  • *p++,*(p++),*++p,(*p)++区别?
  • .net 桌面开发 运行一阵子就自动关闭_聊城旋转门家用价格大约是多少,全自动旋转门,期待合作...
  • .NET企业级应用架构设计系列之开场白
  • .NET业务框架的构建
  • 。Net下Windows服务程序开发疑惑
  • []AT 指令 收发短信和GPRS上网 SIM508/548
  • [14]内置对象
  • [AIGC] Spring Interceptor 拦截器详解
  • [AutoSar]BSW_Memory_Stack_004 创建一个简单NV block并调试
  • [C++]Leetcode17电话号码的字母组合
  • [codeforces]Recover the String
  • [Codeforces1137D]Cooperative Game