如何在 lesscss 中将参数从 mixin 传递到另一个?

发布于 2024-12-05 13:53:23 字数 462 浏览 5 评论 0原文

我在 Drupal 7.8 中使用 LESS CSS 模块 7.x-2.4 我想使用将参数传递给另一个 mixin 的样式 mixin。在示例中,将颜色作为字符串“#CC00CC”传递可以正常工作,但不能作为“darken(@col, 10%)”这样的变量传递。

@bg(@colBg){
  background-color: @colBg; 
}

@style(@col){
  border: 2px solid lighten(@col, 10%); // ok
  @bg(#CC00CC); // ok - color is passed
  @bg(darken(@col, 10%)); // Color is not being passed to @bg
}

.buttonSubmit{
 @style(#FF00FF); 
}

如何实现从 css 类到 mixnin 的级联变量,并将参数传递给另一个 mixin?

I'm using the LESS CSS module 7.x-2.4 in Drupal 7.8
I would like to use style mixins which pass arguments to another mixin. In the example passing the color as a string "#CC00CC" works ok, but not as an variable like that "darken(@col, 10%)".

@bg(@colBg){
  background-color: @colBg; 
}

@style(@col){
  border: 2px solid lighten(@col, 10%); // ok
  @bg(#CC00CC); // ok - color is passed
  @bg(darken(@col, 10%)); // Color is not being passed to @bg
}

.buttonSubmit{
 @style(#FF00FF); 
}

How can I achieve cascading variables from the css-class to a mixnin which passes the argument to another mixin?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叶落知秋 2024-12-12 13:53:23

你的语法不正确。查看关于 mixins 的文档。你的代码应该这样写:

.bg(@colBg){
    background-color: @colBg; 
}

.style(@col){
    border: 2px solid lighten(@col, 10%);
    .bg(#CC00CC);
    .bg(darken(@col, 10%));
}

.buttonSubmit{
    .style(#FF00FF); 
}

Your syntax is incorrect. Check the docs on mixins. The code you have should be written like this:

.bg(@colBg){
    background-color: @colBg; 
}

.style(@col){
    border: 2px solid lighten(@col, 10%);
    .bg(#CC00CC);
    .bg(darken(@col, 10%));
}

.buttonSubmit{
    .style(#FF00FF); 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文