I have been provided with less files containing mixins and styles for LTR as well as RTL content on a webpage. The webpage shows only one type of content at a time, either LTR or RTL. Although I could have separate css for LTR and RTL styles and control which file is being loaded, I want them both to be in the same css file.
The mixins are controlled with an @lang variable as follows:
// file: mixins.less
.myMixin() when (@lang = ltr){
float: left;
}
.myMixin() when (@lang = rtl){
float: right;
}
The mixins are being used in a styles.less file:
// file : styles.less
.myDiv{
.myMixin();
}
I want to output both the ltr and rtl styles in the same css by importing the styles.less file twice but with different value of the @lang variable for each import :
@import "mixin.less";
@lang: ltr;
@import (multiple) "styles.less";
@lang: rtl;
html{
[dir=rtl] & {
@import (multiple) "styles.less";
}
}
But this is obviously not working due to LESS's lazy loading of variables.
Expected output in the css file:
.myDiv {
float:left;
}
[dir=rtl] html .myDiv {
float:right;
}
Actual output in the css file:
.myDiv {
float:right;
}
[dir=rtl] html .myDiv {
float:right;
}
I do not have the liberty to modify the mixins.less file or the styles.less file. How would I go about achieving both ltr and rtl styles in the same css file?
Thanks in advance.
Link for @seven-phases-max : Example
@lang: rtl;
right intohtml {}
block. – seven-phases-max