right-to-left (RTL) support in SASS project

三世轮回 提交于 2019-12-05 05:21:28

not the same approach, but bi-app-sass will solve the rtl problem, and it will generate a 2 different stylesheets for you

after creating the necessary files (explained in the link above), all you have to do is to call a predefined mixin for left / right properties ( float, border, margin, padding, text-align ... )

 .foo {
   @include float(left);
   @include border-left(1px solid white);
   @include text-align(right);
 }

there are also a port of this project for less language


Update

in bi-app-sass there are rtl & ltr conditional mixins that is useful to handle special cases, see the following example

.something {
    @include ltr {
        // anything here will appear in the ltr stylesheet only
        background-image: url( 'app-ltr.jpg' );
    }
    @include rtl {
        // for rtl sheet only
        background-image: url( 'app-rtl.jpg' );
        margin-top: -2px;
    }
}

Note that this feature is not supported in bi-app-less

The following SCSS import adds some useful variables, functions, and mixins.

View on GitHub

Read more

// Override default value for $dir in directional.scss
$dir: rtl;

// Import helpers from directional.scss
@import "directional";

// Use the helpers to make CSS for LTR or RTL
body {
    text-align: $left;
    padding-#{$right}: 1em;
    margin: dir-values(0 2em 0 1em) if-ltr(!important);
}

I would suggest to use a single mixin which can easily handle both cases incl. nested selectors:

_mixin.sass:

$isRLT: true;

@mixin rtl {
  @if $isRLT {
    @if & {
      & {
        @content;
      }
    }
    @else {
      @content;
    }
  }
}

_main.sass:

.test {
  float: left;
  padding: 5px 5px 0px;

  @include rtl {
    padding: 5px 0px 0px 5px;
  }
}

core.scss

// include all your libraries
@import '_mixin';
@import '_main';

This will generate the file without rtl.

For further information check => https://github.com/davidecantoni/sass-rtl-mixin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!