When creating universal margin/padding mixins, it may be necessary to set CSS properties as mixin values. To achieve this, string interpolation is employed.
To use variables as CSS property names, string interpolation (#{$var}) is required.
The following mixin demonstrates how to set CSS properties using string interpolation:
[class*="shift"] {
$sft-o: 10px;
@mixin shift_stp($val) {
&[class*="_sml"]{ #{$val}: $sft-o; }
&[class*="_mid"]{ #{$val}: $sft-o * 2; }
&[class*="_big"]{ #{$val}: $sft-o * 3; }
}
&[class*="_m"]{
@include shift_stp(margin);
}
&[class*="_p"]{
@include shift_stp(padding);
}
}
When using attribute selectors (*="_m"), it's important to consider the potential conflicts with other classes that contain "_mid" within their names.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3