You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SHORT VERSION:
Is the following doable:
.bla {
padding-@variable: 5px; //where @variable could be left, right, top, bottom.
}
INTRO:
I'm working on a website that supports both LTR and RTL. So far I made
two stylesheets, one for LTR and one for RTL. The RTL stylesheet
imports the LTR stylesheet and "overrides" those items that are RTL
specific. (padding-right vs padding-left etc).
float: right/left I manage by having a variable called @SIDE (and
@side-opposite) and setting it to the correct side in both stylesheets
(in RTL it is "right", and in LTR it is "left"). In my LTR stylesheet
I write : float : @SIDE
That was the intro....
QUESTION:
I would also like to eliminate the "overriding" issue, to keep my code
more DRY.
The ultimate thing would be if I could make the property variable:
Gidon, this is in dotless so you could use it as cloudhead suggests.
One issue with this it takes a lot of setting up. instead of potentially having 4 mixins, one each for padding-top, -left, -bottom and -right. you would just have 1.
as an aside. I like the sass sub property syntax...
there's logic in the implementation of course, but not in the stylesheet. It's declarative. Yea, attribute interpolation is powerful, but I don't think we need it.
How would you recommend doing a CSS3 mixin? right now I can do this:
.transition-property(e("box-shadow, top"));
.transition-property(@attr) {
transition-property: @attr;
-webkit-transition-property: e(%("-webkit-%d", @attr));
-o-transition-property: e(%("-o-%d", @attr));
-moz-transition-property: e(%("-moz-%d", @attr));
}
But that only allows for one cross-browser compatible call per selector. :\
I am not entirely sure what an elegant way would be to pull this off, not without iterating through arguments and having logic of some sort to modify the strings. :P As it stands there are only a few properties that you would need to do for this sort of thing, but I am spoiled and dont want to do them all by hand. :P
Gradients are another thing that logic would help with generation. Especially considering the differences in browser syntax at the moment. Right now I have to make different gradient mixins, ones that accept 3 arguments, and ones that accept 2. :D
Probably when 1.5 comes out and no, there is no definitive timeline for that.
There has never been any resistance to this feature, only discussion. Being a library that others rely upon, the developers have be very sure-footed and as forward-looking as possible when they make implementation decisions.
Agreed with @matthew-dean, there isn't resistance to it, but there is limited time. I don't recall seeing @lukeapage mention this as being planned for 1.5, he's super busy atm. @theLucid are you interested in implementing the code for this?
For the specific case of bidirectional sites, I'd like to suggest a more-scoped alternative: Create near and far and replace them with left/right as appropriate. That way your stylesheets remain concise and logic-free, and now actually do a better job of being directionally agnostic.
@TedDriggs what are you referring to? This is a discussion about allowing attributes/properties to have variables in their names. Any references to "left" or "right" are just examples one might use for wanting to add left float and left margin using a mixin.
Activity
cloudhead commentedon Jun 16, 2010
Hey, you can do that with pattern matching, let me illustrate:
Output
So in essence, you can match an arbitrary mixin depending on a variable, instead of creating an arbitrary property name.
jamesfoster commentedon Jun 17, 2010
Gidon, this is in dotless so you could use it as cloudhead suggests.
One issue with this it takes a lot of setting up. instead of potentially having 4 mixins, one each for padding-top, -left, -bottom and -right. you would just have 1.
as an aside. I like the sass sub property syntax...
this outputs as the usual
padding-top: 10px;perhaps it would be possible to store that in a variable?
(I'm just thinking out loud, it's probably not very elegant but looks interesting.)
gjunge commentedon Jun 18, 2010
Looks also nice, though it doesn't look very "lessy", does it?
LESS also doesn't support conditions, or does it?
Because that would also solve it:
.mypadding {
[if @direction="ltr"]
padding-left : 20px;
[else]
padding-right: 20px;
[endif]
}
cloudhead commentedon Jun 18, 2010
the best solution is the one I proposed imo. Cascading stylesheets shouldn't have logic in them, so if/then/else is not an option.
jamesfoster commentedon Jun 18, 2010
:)
I love it when people say things like that.
surely, when i write
.blah(right)there is logic which determines which mixin to mixin!there is logic in less. It just doesn't feel like logic because it doesn't include the word "if".
i still like the
#{}idea from sass, I just think implementing it would be a nightmare.cloudhead commentedon Jun 18, 2010
there's logic in the implementation of course, but not in the stylesheet. It's declarative. Yea, attribute interpolation is powerful, but I don't think we need it.
gjunge commentedon Jun 19, 2010
Yep, I got your point. I can work with the solution provided in less.js
dylan commentedon Jul 8, 2010
How would you recommend doing a CSS3 mixin? right now I can do this:
.transition-property(e("box-shadow, top"));
.transition-property(@attr) {
transition-property: @attr;
-webkit-transition-property: e(%("-webkit-%d", @attr));
-o-transition-property: e(%("-o-%d", @attr));
-moz-transition-property: e(%("-moz-%d", @attr));
}
But that only allows for one cross-browser compatible call per selector. :\
jamesfoster commentedon Jul 8, 2010
How would you prefer to use it?
dylan commentedon Jul 8, 2010
I am not entirely sure what an elegant way would be to pull this off, not without iterating through arguments and having logic of some sort to modify the strings. :P As it stands there are only a few properties that you would need to do for this sort of thing, but I am spoiled and dont want to do them all by hand. :P
dylan commentedon Jul 8, 2010
Gradients are another thing that logic would help with generation. Especially considering the differences in browser syntax at the moment. Right now I have to make different gradient mixins, ones that accept 3 arguments, and ones that accept 2. :D
cloudhead commentedon Jul 8, 2010
Hmm, could you show me the desired CSS output, maybe in a Gist, and I'll see if I can think of anything.
dylan commentedon Jul 8, 2010
http://gist.github.com/468428
dancrew32 commentedon Mar 3, 2011
Here's my LTR/RTL variable solution: http://stackoverflow.com/questions/5121584/less-how-to-insert-an-variable-into-property-as-opposed-to-the-value/5162599#5162599
dylan commentedon Mar 11, 2011
nice!
18 remaining items
Soviut commentedon Jun 29, 2013
Probably when 1.5 comes out and no, there is no definitive timeline for that.
There has never been any resistance to this feature, only discussion. Being a library that others rely upon, the developers have be very sure-footed and as forward-looking as possible when they make implementation decisions.
jonschlinkert commentedon Jun 29, 2013
Agreed with @matthew-dean, there isn't resistance to it, but there is limited time. I don't recall seeing @lukeapage mention this as being planned for 1.5, he's super busy atm. @theLucid are you interested in implementing the code for this?
Soviut commentedon Jun 29, 2013
Link the pull request if you can. I'm sure if it was rejected that there was a good reason for it.
TedDriggs commentedon Aug 16, 2013
For the specific case of bidirectional sites, I'd like to suggest a more-scoped alternative: Create
nearandfarand replace them withleft/rightas appropriate. That way your stylesheets remain concise and logic-free, and now actually do a better job of being directionally agnostic.Soviut commentedon Aug 16, 2013
@TedDriggs what are you referring to? This is a discussion about allowing attributes/properties to have variables in their names. Any references to "left" or "right" are just examples one might use for wanting to add left float and left margin using a mixin.
cloudhead commentedon Aug 16, 2013
Given that we've introduced variable interpolation in selectors since then, I'd say it's OK (if not expected) to have it in property names too now.
jonschlinkert commentedon Aug 16, 2013
👍
Soviut commentedon Aug 16, 2013
👍 agreed
seven-phases-max commentedon Oct 14, 2013
Above. I did not create a pull-request to the master repo yet as I guess it would probably be too dramatic change for 1.5.0-beta at the last moment.
cwygoda commentedon Dec 14, 2013
👍
lukeapage commentedon Feb 13, 2014
In 1.6.0