Skip to content
On this page

关键字参数

Stylus 支持关键字参数,或称为 "kwargs"。这些允许你通过其关联的参数名引用参数。

下面展示的示例在功能上是等效的。但是,我们可以 将关键字参数放置在列表中的任何位置。未被键控的剩余参数 将应用于尚未满足的参数。

stylus
body {
  color: rgba(255, 200, 100, 0.5);
  color: rgba(red: 255, green: 200, blue: 100, alpha: 0.5);
  color: rgba(alpha: 0.5, blue: 100, red: 255, 200);
  color: rgba(alpha: 0.5, blue: 100, 255, 200);
}
body {
  color: rgba(255, 200, 100, 0.5);
  color: rgba(red: 255, green: 200, blue: 100, alpha: 0.5);
  color: rgba(alpha: 0.5, blue: 100, red: 255, 200);
  color: rgba(alpha: 0.5, blue: 100, 255, 200);
}

生成:

css
body {
  color: rgba(255,200,100,0.5);
  color: rgba(255,200,100,0.5);
  color: rgba(255,200,100,0.5);
  color: rgba(255,200,100,0.5);
}
body {
  color: rgba(255,200,100,0.5);
  color: rgba(255,200,100,0.5);
  color: rgba(255,200,100,0.5);
  color: rgba(255,200,100,0.5);
}

要查看函数或混合器接受哪些参数,请使用 p() 函数:

stylus
p(rgba)
p(rgba)

生成:

bash
inspect: rgba(red, green, blue, alpha)
inspect: rgba(red, green, blue, alpha)

Released under the MIT License.