【问题标题】:Set variable to a new value if a specific class is present in LESS如果 LESS 中存在特定类,则将变量设置为新值
【发布时间】:2018-10-05 22:41:36
【问题描述】:

用一个例子很容易解释我想要什么。

我想实现类似的目标

.someClass {
   @aVariable: 100px;
   /*
   if(along with .someClass .anotherClass is present) {
      @aVariable = 200px;
   }
   */
   /*@aVariable is used here */
}

重点是根据另一个班级的存在来设置@aVariable

我看到了the 的回答,但对我没有用。

【问题讨论】:

  • 如果你描述你的实际目标而不是你认为你将如何实现它会更好(例如,它实际上是一个 XY 问题)。问题是为什么你需要那个变量以及如何你将要使用它。 (上面你想要的方式根本不可能,因为变量和类定义都不像在 Less 中那样工作)。

标签: css if-statement less


【解决方案1】:
.someClass {
   @aVariable: 100px;

   /*@aVariable should be used here */

   &.anotherClass {
       @aVariable: 200px;

    /*2nd @aVariable should be used here. this will overide above css*/
   }
}

【讨论】:

  • 我想这样做是为了避免为新的@aVariable 值重复在.anotherClass 之外写入的内容。但是您的解决方案无助于实现这一目标,但仍然感谢。
猜你喜欢
  • 2013-08-27
  • 1970-01-01
  • 1970-01-01
  • 2021-05-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-17
相关资源
最近更新 更多