stylus预处理入门(三)--插值

stylus预处理入门(三)--插值

转载原地址:http://www.jianshu.com/p/7b8acb85f1b5

插值(interporation)

插值相当于解析表达式或者变量,让它们的值替换插值的位置。
注: 不能用于属性值的插值(但属性值可以使用变量替换)。

  • 在css属性名中使用插值
partOfProp = radius
value = 10px
div
    border-{partOfProp} value  /*切记属性值这里不可以使用插值*/

转化:

div {
  border-radius: 10px;
}
  • 在选择器中使用插值
selector = div
partOfProp = radius
value = 10px
{selector}
    border-{partOfProp} value

转化:

div {
  border-radius: 10px;
}
selectors = '#foo,#bar,.baz'

{selectors}
  background: #000

转化:

#foo,
#bar,
.baz {
  background: #000;
}

高级使用:与mixins配合使用

  vendor(prop, args)
    -webkit-{prop} args
    -moz-{prop} args
    {prop} args

  border-radius()
    vendor('border-radius', arguments)

  box-shadow()
    vendor('box-shadow', arguments)

  button
    border-radius 1px 2px / 3px 4px

转化

  button {
    -webkit-border-radius: 1px 2px / 3px 4px;
    -moz-border-radius: 1px 2px / 3px 4px;
    border-radius: 1px 2px / 3px 4px;
  }

高级使用:与循环迭代(iteration)配合使用

table
  for row in 1 2 3 4 5
    tr:nth-child({row})
      height: 10px * row

转化:

table tr:nth-child(1) {
  height: 10px;
}
table tr:nth-child(2) {
  height: 20px;
}
table tr:nth-child(3) {
  height: 30px;
}
table tr:nth-child(4) {
  height: 40px;
}
table tr:nth-child(5) {
  height: 50px;
}
 

转载于:https://my.oschina.net/fadoudou/blog/1477113

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值