css - Mixins:实现有困难

标签 css less mixins

是否可以从此混音中仅选择 border-top。 现在我只需要顶部边框,但想收集它们以供使用。我想为每个侧边框使用单独的 mixin 是错误的,

 .bordered(@top-width: 1px, @top-color: #fff, @bottom-color: #fff) { 
     border-top: @top-width solid @top-color; 
     border-left: @top-width solid @left-color; 
     border-right: @top-width solid @right-color; 
     border-bottom: @top-width solid @bottom-color; }

我想为两者使用相同的 mixin 来获得此输出

.class1{border-top:6px solid red;}
.class2{border-bottom:1px solid white;} 

谢谢

最佳答案

您可以创建一个 mixin,在其中传入您想要的边框类型。这样你就可以只拥有一个多次调用的 mixin。

此 mixin 使用 Less v1.6+ 中可用的属性插值

http://lesscss.org/features/#variables-feature-properties

.border(@property; @value){
  border-@{property}: @value;       
}

.bacon {
  .border(top; 1px solid black);
}

// Outputs
.bacon {
  .border-top: 1px solid black;
}

关于css - Mixins:实现有困难,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24471437/

相关文章:

html - 以第二个为中心的中心 3 不对称 div

CSS 渐变 - 更少的混合

css - 使用 nodejs gulp 在 Less 中导入 .css 文件

javascript - 重构遗留的基于 mixin 的类层次结构

css - 通过SASS函数自动生成css变量

JavaScript 显示 div 并在倒计时结束时添加类

jquery - 具有过滤器亮度背景的div中的文本颜色

html - 如何在 Less 的子类中对祖 parent 应用条件

css - 如何使用 compass 和 scss 要求混合(来自配置)

html - 如何删除由于 CSS 相对位置而导致的空白?