【问题标题】:Stylus. Negative variables手写笔。负变量
【发布时间】:2015-02-25 03:40:06
【问题描述】:

如何在 Stylus 中使用负变量?

我为精灵写了 mixin:

sprite-medium(col,row)
  width = 40px
  height = 40px
  width: width
  height: height
  background: url('../img/medium-sprite.png') no-repeat
  background-position: -col*width -row*height

我有一个错误。当然,我可以在 mixins 的调用中写入负值,但这不是一个完美的决定。任何人都可以帮忙吗?谢谢。

【问题讨论】:

标签: stylus


【解决方案1】:

Stylus 将 colrow 之前的 - 视为名称的一部分 - 需要将它们分开才能像 -(col * width) 一样工作,但是您还需要避免减去两个值想要背景位置。这是一个具有工作背景计算的解决方案,并通过使用属性查找进行了一些简化:

sprite-medium(col, row)
  width: 40px
  height: 40px
  background: url('../img/medium-sprite.png') no-repeat
  background-position: -(col * @width) -1 * (row * @height)

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多