Stylus入门教程--实例(1)

stylus

1、安装与自动编译

  • 新建example文件夹
  • 新建/example/dist文件夹
  • 打开命令行界面 输入 stylus -w demo.styl -o dist
  • -w 是自动监视文件 -o 是将编译后的CSS文件输出到指定文件中
  • 在demo.styl里面写内容,保存即可

2、变量( variables)

  • 默认值
position()
  position: arguments
  z-index: 1 unless @z-index

#logo
  z-index: 20
  position: absolute

#logo2
  position: absolute

编译后

#logo {
  z-index: 20;
  position: absolute;
}
#logo2 {
  position: absolute;
  z-index: 1;
}
  • 就近原则
body
  color: red
  ul
    li
      color: blue
      a
        background-color: @color

编译后

body {
  color: #f00;
}
body ul li {
  color: #00f;
}
body ul li a {
  background-color: #00f;
}

3、运算符(operators)

  • Stylus近乎一切都是true, 包括有后缀的单位,甚至0%, 0px等都被认作true.
    不过,0在算术上本身是false.
    表达式(或“列表”)长度大于1被认为是真。
    true例子
0% 
0px
1px 
-1
-1px
hey
'hey'
(0 0 0)
('' '')

false例子

0  
null 
false 
''
  • 实例检查:is a

Stylus提供一个二元运算符叫做is a, 用做类型检查。

15 is a 'unit'
// => true

#fff is a 'rgba'
// => true

15 is a 'rgba'
// => false

类似的,我们可以使用type()这个内置函数。

 type(#fff) == 'rgba'
// => true

注意:color是唯一的特殊情况,当左边是RGBA或者HSLA节点时,都为true.

未完待续!!!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值