【问题标题】:Is there a way to add a mixin into a variable in LESS有没有办法在LESS中将mixin添加到变量中
【发布时间】:2014-04-14 18:28:04
【问题描述】:

我可以向 LESS 中的变量添加 mixin 吗?

类似的东西

@input-border-radius: .rounded();
or
@h1: .font-size(46) // This pulls from the rem calculator mixin.

查看了 LESS Docs 但找不到方法。

【问题讨论】:

  • 简而言之,不,您不能直接将mixin分配给变量。然而,在 Less 1.7.0 中引入了所谓的"detached ruleset" 功能,因此可以间接地做到这一点,例如:@input-border-radius: {.rounded()};@h1: {.font-size(46)};(其余的取决于你的进展情况实际使用这些变量)。
  • Seven-phases-max,这有多新,因为我在另存为 sublime 文本时遇到错误

标签: variables less mixins


【解决方案1】:

有办法。

您可以定义(可能是虚构的)类的属性,并以不同类的样式调用该类的属性。例如:

.fontstyling {
   font-weight: bold;
   color: black;
}

h1 {
   font-size: 46px;
   .fontstyling;
}

h2 {
   font-size: 38px;
   .fontstyling;
}

(这不是格式化标题的最佳方式 - 但对于其他示例,它真的很有用!)

【讨论】:

  • 谢谢,但我使用的是 REM Mixin,它计算 px 并将其转换为 rem,所以这对我不起作用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-20
  • 1970-01-01
  • 2021-05-15
  • 1970-01-01
  • 2012-01-11
相关资源
最近更新 更多