.inputbase() {
/* your base code */
}
.someInput {
.inputbase;
/*some input special code */
}
.someOtherInput {
.inputbase;
/*some other input special code */
}
.andAnotherInput {
.inputbase;
/*and another input special code */
}
CSS 输出
.someInput {
/* your base code *//*some input special code */
}
.someOtherInput {
/* your base code *//*some other input special code */
}
.andAnotherInput {
/* your base code *//*and another input special code */
}
.inputbase {
/* your base code */
}
.someInput {
&:extend(.inputbase);
/*some input special code */
}
.someOtherInput {
&:extend(.inputbase);
/*some other input special code */
}
.andAnotherInput {
&:extend(.inputbase);
/*and another input special code */
}
CSS 输出
.inputbase,/* this is gone once mixin extending allows .inputbase() extension */
.someInput,
.someOtherInput,
.andAnotherInput {/* your base code */}
.someInput {/*some input special code */}
.someOtherInput {/*some other input special code */}
.andAnotherInput {/*and another input special code */}
优点在于所有基础代码没有重复,但重复的是选择器,因为它们首先与基础代码一起分组,然后再针对个别代码输出。如果一个人喜欢将他们的代码分组在一个选择器定义中,那么这不是一个好的方法。否则,这提供了一种减少CSS输出的好方法。 3. 两个类(您提议的额外HTML标记) 您提出的这个解决方案具有两个类别(这是因为您表示您不总是希望将 ".inputbase" 应用于输入元素)。 LESS 和 CSS 输出*
.inputbase {
/* your base code */
}
.someInput {
/*some input special code */
}
.someOtherInput {
/*some other input special code */
}
.andAnotherInput {
/*and another input special code */
}
input {
/* your base code */
}
.someInput {
/*some input special code *//*override input base code if needed */
}
.someOtherInput {
/*some other input special code *//*no override if not needed */
}
.andAnotherInput {
/*and another input special code *//*no override if not needed */
}