美文网首页
用npm安装sass教程

用npm安装sass教程

作者: Nelson_sylar | 来源:发表于2018-11-15 14:02 被阅读0次

先安装npm 再在shell里依次输入

这里就安装好了,我们试试吧

  • mkdir ~/Desktop/scss-demo
  • cd ~/Desktop/scss-demo
  • mkdir scss css
  • touch scss/style.scss
  • start scss/style.scss

用node-sass 命令将scss转换为css

  • node-sass -wr scss -o css

这里我们以动态rem为例,用sass写一个函数输入像素,输出对应的rem值
编辑 scss 文件就会自动得到 css 文件

在 scss 文件里添加

```
@function px( $px ){
  @return $px/$designWidth*10 + rem;
}

$designWidth : 640; // 640 是设计稿的宽度,你要根据设计稿的宽度填写。如果设计师的设计稿宽度不统一,就杀死设计师,换个新的。

.child{
  width: px(320);
  height: px(160);
  margin: px(40) px(40);
  border: 1px solid red;
  float: left;
  font-size: 1.2em;
}

```

即可实现 px 自动变 rem

相关文章

网友评论

      本文标题:用npm安装sass教程

      本文链接:https://www.haomeiwen.com/subject/xrlyfqtx.html