css - LESS contrast() 函数

标签 css webkit less mozilla

您可能知道 LESS 提供了许多面向色彩的操作(例如:darken()lighten()mix())他们都工作得很好。 不幸的是,我无法使用理论上最酷的功能之一:自动设置与您提供的颜色形成对比的颜色的功能。 来自官方 LESS 规范:

contrast(@color1, [@darkcolor: black], [@lightcolor: white], [@threshold: 43%]); 

所以,我的 LESS 基本上提供了一个可以变化很大的背景变量(我正在开发基于主题的网站),并且它的文本颜色应该适应。

   &.popup{
      .body{
         background-color: @popupBg;
         color: contrast(@popupBg, [@darkcolor: black], [@lightcolor: white], [@threshold: 43%]);
      }
   }

在控制台中检查输出代码时,我可以看到函数未正确解析(Chrome 通知错误,Firefox 只是隐藏它)。我还尝试了简化版本,它只是 color: contrast(@popupBg); 并没有运气。

有人用过这个吗?我已经使用 LESS 很多次了,这是第一次遇到问题。

最佳答案

方括号表示可选参数,不应出现在您的代码中。查看 LESS 函数引用及其 documentation on contrast ,它有一个关于如何正确使用对比度的例子:

Example:

contrast(#aaaaaa)
contrast(#222222, #101010)
contrast(#222222, #101010, #dddddd)

Output:

#000000 // black
#ffffff // white
#dddddd

所以你的代码应该是:

color: contrast(@popupBg, black, white, 43%);

另一方面,您确定 @popupBg 已定义吗?

查看 this jsfiddle用于演示。

关于css - LESS contrast() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18505929/

相关文章:

html - Safari 中的元素定位和 css 翻译问题

css - 在 -webkit-gradient 中堆叠渐变

html - 垂直居中对齐 Bootstrap 响应式网格

javascript - 无法使用 jquery 更改悬停在 <a> 上的跨度

javascript - 在 JS/CSS 中调整 SVG 的高度

perl Gtk2::WebKit: 如何做一个整页截图

html - 当我将她移到顶部时,我的 div 的一部分被隐藏了

css - :not selector for all inputs they are not in a UL with class . 输入列表?

javascript - LESS.js - 错误消息 "failed to save"

css - 网站填充