Question

Par exemple, j'ai ensuite moins de code

form.someForm
{
    .form-group
    {
        > div
        {
            @media @wideMobile
            {
                width: calc(~"100%-144px");            
            }
        }

        > label
        {
            @media @wideMobile
            {
                width: 138px;            
            }
        }

    }
}  

Je veux écrire quelque chose comme

form.someForm
{
    .setWidths(138px,144px); 
}

Pour obtenir le même résultat.Comment puis-je faire ça?

Était-ce utile?

La solution

Je suppose que tous ces exemples à Les docs pourraient émaner quelques idées:

form.someForm {
    .setWidths(138px, 144px);
}

// the mixin:

.setWidths(@labelWidth, @divMargin) {
    .form-group {
        > div {
            @media @wideMobile {
                width: calc(100% ~'-' @divMargin);
            }
        }

        > label {
            @media @wideMobile {
                width: @labelWidth;
            }
        }
    }
}

ou même plus court (si les descendants partagent la même requête de média):

.setWidths(@labelWidth, @divMargin) {
    .form-group {
        @media @wideMobile {
            > div   {width: calc(100% ~'-' @divMargin)}
            > label {width: @labelWidth}
        }
    }
}

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top