An approach to write a css code for once and create two version of it RTL or LTR just with change one variable value
_direction-controller.scss: It's main file to handle directions and have to import after $text-direction variable.
$text-direction: Main variable to change css output for RTL / LTR websites. Default value is ltr- Direction Controller base is for LTR languages. If you want change default coding Sass structure for RTL languages, change default value of these variables:
$default-float: Default value is left$opposite-direction: Default value is right
$text-direction: Main variable to choose direction. Default value is ltr$start: If $text-direction value equal ltr,$startvalue is left$end: If $text-direction value equal ltr,$endvalue is right
dir-check($a, $b): This function check if direction equal ltr return first parametr, else return secound parameterdir-values($values): Reorder right and left positions in padding/margin values listbr-values($values): Reorder right and left positions in border-radius values list
if-ltr() { @content }: This Mixin check your direction and if your direction was ltr load content of this mixin.if-rtl() { @content }: This Mixin check your direction and if your direction was rtl load content of this mixin.
Read details on this article(Persian): http://parhum.net/blog/ui/sass-direction-controller/
- Add main file to bower.json.
- Add bower.json and register it to bower library.
- Add
$default-float&$opposite-directionvariables to can change base Sass structure for LTR / RTL. Default structure is forLTRlanguages
- Change
$left&$rightvariable names to$start&$end
- initial release