在LESS中正确使用'Mixins'

时间:2012-05-29 22:00:08

标签: css less mixins

我正在尝试使用较少的创建简单的“模板”,但我想我可能会这样做不正确..

这就是我想要的:

<div class='box'>content</div>

和.less文件:

//this is the mixin

.blueBoxNotificationDiv {
    text-decoration: none !important;
    position: absolute;
    background: #EBEBEB;
    width: 100%;
    border-top: 1px solid #999;
    bottom: 0;
    height: 21px;
}

现在让我们说我想把这个'mixin'应用到div'.box'。 这就是我将它写在.less中的方式:

.box {
    .blueBoxNotificationDiv;
}

解决这个问题的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

如果没有正确写出(包括规则),LESS变量将阻止在较少的文件中读取任何其他内容。

问题示例:

@color1: #000000;
@color2: #ffffff;
@color3: ##e6e6e6;

.container {
    color:@color1;
}

.....etc

这应该是非常明显的,但很容易错过小错误。变量'@ color3'有两个散列'##'。如果你不调用变量,这将打破较少的偶数,并且不会读取以下代码(我可以告诉附近)。问题解决了!