例如,我有下一个少量代码

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}
        }
    }
}
.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top