【问题标题】:Less (css) - possible adding multiple tags and properties in one block?Less (css) - 可以在一个块中添加多个标签和属性吗?
【发布时间】:2022-08-09 11:34:16
【问题描述】:

样式化 css 与少.js预处理器我有类似的东西:

 a,a:hover,a:focus,a:active,a:link,a:visited {
    text-decoration: hsl(46, 27%, 5%);
    font-weight: inherit;
    ... <other props>
    border-bottom: 1px solid hsl(200, 99%, 10%);
}

是否可以使用 Less 将上面的整个块包装在某种类、函数、规则集或变量中,并在需要时在其他任何地方使用它(在其他类、样式、选择器、标签中)?

例如,希望类似:

.myHrefStyle() {
  
   a,a:hover,...{
      text-decoration: hsl(46, 27%, 5%);
      ... 
      border-bottom: 1px solid hsl(200, 99%, 10%);
   }

}

然后在其他地方重用它:

.otherClass {
    .myHrefStyle()
}

标签: css less


【解决方案1】:

分离的规则集应该可以工作。 Documentation

// Declare detached ruleset
@myHrefStyle: {

    a,
    a:hover,
    a:focus,
    a:active,
    a:link,
    a:visited {
        text-decoration: hsl(46, 27%, 5%);
        font-weight: inherit;
        border-bottom: 1px solid hsl(200, 99%, 10%);
    }

};

.otherClass {
    @myHrefStyle(); // Use detached ruleset
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-29
    • 2011-02-07
    • 2015-06-11
    • 2014-04-26
    • 1970-01-01
    • 2010-09-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多