css - 更少的带有颜色名称的 css 变量

标签 css less

我正在尝试创建一些动态类宽度更少的 css。

这个想法是在html这个类中使用的:

.color-white{
   color: white !important;
}

我在 Less 中创建了这个 sintaxis:

.change-color(@which; @color){
  .color-@{which}{
    color:@color !important;
  }
  .background-@{which}{
    background-color:@color !important;
  }
}

所以,有了这个我想接受我的想法:D

.change-color(@which: white; @color: white);

但是,这就是问题所在,我有这个:

.color-#ffffff{
  color:#fff!important
}
.background-#ffffff{
  background-color:#fff!important
}

如何将“white”用作字符串而不是十六进制颜色。

谢谢。

最佳答案

改为这样调用:

.change-color(@which: ~'white'; @color: ~'white');

尽管我认为直接创建一个名为 .color-red 的类比无缘无故地让事情变得更难读会更好。

关于css - 更少的带有颜色名称的 css 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23958891/

相关文章:

css - 我的 CSS 在 "sails lift --prod"时无法正常工作,就像在 "sails lift"时一样

html - Bootstrap 响应式 div 折叠

css - 如何删除 LESS 中的重复属性

visual-studio-2013 - 在 Visual Studio 中编译 .less 文件而不需要 Web 必需品?

CSS 过滤器属性不起作用?

twitter-bootstrap - Twitter Bootstrap ".container"类 : How to use it semantically?

css - 是否有可能出现文本溢出 : ellipsis without white-space: nowrap?

javascript - 在 Electron 中更改可拖动区域上的光标

html - 表格的黑色细边框

第一页加载时的 CSS 问题 - Bootstrap 3