(ps: cnpm node gulp 全局安裝一次,默認以前都有了;局部安裝 gulp 輸入:cnpm install gulp --save-dev )
------------------------------------------------------【html頁面-------------------------------------------------------------
<!doctype html>
<html>
<head>
<title>我是首頁</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=100%, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no" />
<meta content="telephone=no" name="format-detection" />
<meta name="apple-mobile-web-app-title" content="">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-touch-fullscreen" content="yes">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta http-equiv="x-ua-compatible" content="ie=edge,chrome=1">
<link href="static/css/out/base.css" type="text/css" rel="stylesheet" />
<link href="static/css/out/main.css" type="text/css" rel="stylesheet" />
</head>
<body>
<ul class="list">
<li>菜單1</li>
<li>菜單2</li>
</ul>
<button class="button">肯定</button>
</body>
</html>
------------------------------------------------------html頁面】-------------------------------------------------------------
------------------------------------------------------【關鍵css片斷----------------------------------------------------------
html {
font-size: 20px;
}
@media only screen and (min-width: 400px) {
html {
font-size: 21.33px !important;
}
}
@media only screen and (min-width: 414px) {
html {
font-size: 22.08px !important;
}
}
@media only screen and (min-width: 480px) {
html {
font-size: 25.6px !important;
}
}
$browser-default-font-size: 40px !default;
@function pxToRem($px) {
//$px爲須要轉換的字號
@return $px / $browser-default-font-size * 1rem;
}
------------------------------------------------------關鍵css片斷】----------------------------------------------------------
在項目裏面,右鍵新建,gulpfile.js文件
開始寫任務
------------------------------------------------------【gulpfile.js片斷----------------------------------------------------------
var gulp=require("gulp");
var browserSync=require("browser-sync");
var sass=require("gulp-sass");
gulp.task("server",["listenProduct","buildSass"],function(){
console.log("server is starting.....");
browserSync.init({
server:"./dev",
port:8383,
reloadDelay:500,
notify:true,
files:[
"./dev/*.html",
"./dev/static/css/def/scss/*.scss",
"./dev/static/css/out/*.css",
"./src/static/js/def/*.js",
"./src/static/js/out/*.js",
]
});
});
gulp.task("listenProduct",function(){
gulp.watch("./dev/static/css/def/scss/*.scss",["autoBuildConcat"]);
});
gulp.task("autoBuildConcat",function(){
runSequence("buildSass");
});
gulp.task("buildSass",function(){
console.log("buildSass")
return gulp.src('./dev/static/css/def/scss/*.scss')
.pipe(sass({
outputStyle:"expanded"
}))
.pipe(gulp.dest("./dev/static/css/out/"));
});
gulp.task("default",function(){
gulp.start("server");
});
涉及到以前已略有介紹此相關
這裏只顯示主要內容片斷
------------------------------------------------------
gulpfile.js片斷】----------------------------------------------------------
在main.scss裏面寫
.button{
width: pxToRem(100px);
height:pxToRem(100px);
display: block;
margin: 0 auto;
text-align: center;
}
這樣以後
dos下輸入 gulp 一個命令 便可自動打開以下 頁面,實現了:自動刷新,px rem換算 ,sass css轉換
且,經過如此配置, 你能夠,爲所欲爲的使用sass,而不是再去借助於考拉工具
這裏,能夠沒必要在去口算,心算psd的具體寬度,高度
psd上面,是多少,就寫多少
這裏,已經幫你配置好,換算好
(ps:描述過程當中的截圖,是爲了更好的匹配選擇,減小彎路過程;加粗或背景是重點。)
多謝,田兄,一路指點,方可完善。
下載地址 ;http://files.cnblogs.com/files/leshao/auto01.rar