美文网首页
Stylus学习

Stylus学习

作者: 湘兰沅芷 | 来源:发表于2019-03-22 16:15 被阅读0次

文章出自[译]为什么使用Stylus - 潘无处不在 - 博客园

css预处理器的出现,提高了前端开发的效率,让css可编程化。

常见的预处理器:less、sass/scss、stylus。

Less:

less外围社区环境和社区成员为他提供了大量的资源(Twitter Bootstrap)的框架;

less的第三方库LESShat,提供了一系列针对CSS3效果的混写规则,还拥有针对Photoshop的插件CSShat,能够方便的识别PSD文件生成LESS代码。

less非常容易上手使用。

less逻辑处理:less只提供了少量的逻辑处理特性,代码编写缓慢后期维护成本高。

在LESS里面没有if/else判断,所以上面的代码就无法实现。你最多能用用所谓“Guarded Mixins”的方法,基于单条表达式的判断,就像这样:

.border_and_bg ( @border_on, @border_color, @bg_on, @bg_color ) when (@border_on =true) {border:1px solid @border_color;}

Sass:

1.拥有活跃的社区,优质的资源(Gumby和Foundation)(Compass和Bourbon)

2.逻辑处理上神,像一个复杂的编程语言。

举个例子,Sass能让你写出有效的条件检查,这很有用,尤其是在混写中。

@mixin border_and_bg( $border_on, $border_color, $bg_on, $bg_color ){    @if$border_on ==true{border:1px solid $border_color;    } @else{border:0;    }    @if$bg_on ==true{        background-color: $bg_color;    } @else{        background-color: transparent;    }}

这段代码检测$border_on是否为true,为true则输出的border颜色属性值为$border_color的值。如果为false则设置border属性为0。

同时它还检测了$bg_on是否为true,为true则输出background-color值为$bg_color的值。为false的话设置background-color为transparent。

这样,根据输入的值,我们就可以输出四种不同的样式。

如果要实现Sass中同样的功能,你需要用LESS创建四条不同的混写,就像这样:

.border_and_bg ( @border_on, @border_color, @bg_on, @bg_color ) when (@border_on =true) and (@bg_on =true) {border:1px solid $border_color;  background-color: @bg_color;}.border_and_bg ( @border_on, @border_color, @bg_on, @bg_color ) when (@border_on =false) and (@bg_on =false) {border:0;  background-color: transparent;}.border_and_bg ( @border_on, @border_color, @bg_on, @bg_color ) when (@border_on =false) and (@bg_on =true) {border:0;  background-color: @bg_color;}.border_and_bg ( @border_on, @border_color, @bg_on, @bg_color ) when (@border_on =true) and (@bg_on =false) {border:1px solid @border_color;  background-color: transparent;}

相关文章

  • Stylus学习笔记

    stylus学习 选择器 缩进语法(必学,必用) stylus最贱写法在stylus中 冒号,分号,大括号 都是可...

  • stylus学习

    1、stylus:富于表现力、动态的、健壮的 CSS stylus的文档说明stylus的github张鑫旭中文翻...

  • Stylus学习

    文章出自[译]为什么使用Stylus - 潘无处不在 - 博客园 css预处理器的出现,提高了前端开发的效率,让c...

  • vue cli3.0中引用stylus文件

    首先安装 stylus和stylus-loader npm install stylus --save 和 npm...

  • 如何在wepy中使用stylus

    如何在wepy中使用stylus 第一步,安装wepy-compiler-stylus(以及stylus, sty...

  • TypeError: this.getOptions is no

    vue 安装stylus和stylus-loader 提示如下截图错误信息 环境:node@12原因:stylus...

  • Vue2.X部分常用配置

    1.全局配置css预编译语言,如stylus 前提需先安装stylus, 1.1 npm i stylus-loa...

  • [记录] [CSS预处理器]Stylus in Vue

    为什么选择Stylus做预处理呢? 那么在SaaS,Less和Stylus中,为什么选择后者呢?因为Stylus是...

  • stylus

    https://www.zhangxinxu.com/jq/stylus/http://stylus-lang.com/

  • Stylus预处理器简介(二十五)连接中间件

    连接中间件 Stylus附带了Connect中间件,用于在Stylus表被修改时自动编译它们。 stylus.mi...

网友评论

      本文标题:Stylus学习

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