Skip to content

Instantly share code, notes, and snippets.

@Mosharush
Created May 5, 2020 16:38
Show Gist options
  • Save Mosharush/18579f57db5a7998940f85cfa8fd4c08 to your computer and use it in GitHub Desktop.
Save Mosharush/18579f57db5a7998940f85cfa8fd4c08 to your computer and use it in GitHub Desktop.
RTL-LTR Both support css design - Scss Mixins
<div class="item"></div>
<style lang="scss">
.item {
position: relative;
@include padding_right_rtl(5px);
@include rtl('right', 0, 0, 'left')
}
</style>
// RTL Mixins start
@mixin rtl($property, $ltr-value, $rtl-value, $ltr-property: false) {
& {
@if $ltr-property {
#{$ltr-property}: $ltr-value;
}
@else {
#{$property}: $ltr-value;
}
}
[dir='rtl'] & {
#{$property}: $rtl-value;
}
}
@mixin rtl_modern(
$property,
$ltr-value,
$rtl-value,
$modern-property: false,
$modern-value: false
) {
@if $modern-property {
@supports not ($modern-property: $modern-value) {
@include rtl($property, $ltr-value, $rtl-value);
}
#{$modern-property}: $modern-value;
} @else {
@include rtl($property, $ltr-value, $rtl-value);
}
}
@mixin padding_left_rtl($value) {
@include rtl_modern(padding, 0 $value 0 0, 0 0 0 $value, padding-inline-end, $value);
}
@mixin padding_right_rtl($value) {
@include rtl_modern(padding, 0 0 0 $value, 0 $value 0 0, padding-inline-start, $value);
}
@mixin margin_left_rtl($value) {
@include rtl_modern(margin, 0 $value 0 0, 0 0 0 $value, margin-inline-end, $value);
}
@mixin margin_right_rtl($value) {
@include rtl_modern(margin, 0 0 0 $value, 0 $value 0 0, margin-inline-start, $value);
}
// RTL Mixins end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment