题
例如,我有下一个少量代码
form.someForm
{
.form-group
{
> div
{
@media @wideMobile
{
width: calc(~"100%-144px");
}
}
> label
{
@media @wideMobile
{
width: 138px;
}
}
}
}
.
我想写像
这样的东西form.someForm
{
.setWidths(138px,144px);
}
.
以获得相同的结果。我该怎么办?
解决方案
我猜我在 docs 可以发出一些想法:
form.someForm {
.setWidths(138px, 144px);
}
// the mixin:
.setWidths(@labelWidth, @divMargin) {
.form-group {
> div {
@media @wideMobile {
width: calc(100% ~'-' @divMargin);
}
}
> label {
@media @wideMobile {
width: @labelWidth;
}
}
}
}
.
甚至更短(如果后代共享相同的媒体查询):
.setWidths(@labelWidth, @divMargin) {
.form-group {
@media @wideMobile {
> div {width: calc(100% ~'-' @divMargin)}
> label {width: @labelWidth}
}
}
}
. 不隶属于 StackOverflow