I am wondering if it is possible to create a mixin that treats several arguments as properties that need to be converted to rtl. I want to do something like
.css-selector { width: 300px; height: 200px; @include rtl { padding: 10px 5px 3px 4px; margin: 3px 8px 2px 5px; } }
with the mixture:
$rtl = false !default; @mixin rtl() { @if $rtl { dir: rtl; @each $property in @content { //check property if it padding or margin or something else rtl-related... if hit use rtl mixin } } @else { @content; } }
I think I should parse @content, but it doesn't work (invalid CSS after "... h $ property in": the expected expression (e.g. 1px, bold) was "@content {).
Now I am processing rtl with two vars:
$dir: left !default; $opdir: right !default;
which I change when it is rtl. I use it in my sass files, for example
margin-#{$dir}: 15px;
But I do not think that this solution is quite flexible. And I also don't want to include a separate mixin for the css property.
Does anyone have a better idea or solution? Any feedback is appreciated.
source share