Skip to content

关键字参数

¥Keyword Arguments

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

¥Stylus supports keyword arguments, or "kwargs". These allow you to reference arguments by their associated parameter name.

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

¥The examples shown below are functionally equivalent. However, we can place keyword arguments anywhere within the list. The remaining arguments that are not keyed will be applied to the parameters that have not been satisfied.

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);
}

产量:

¥Yielding:

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);
}

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

¥To see what parameters a function or mixin accept, use the p() function:

p(rgba)
p(rgba)

产量:

¥Yielding:

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