Designate a mixin as !important
When calling a mixin (parametric or otherwise), if the call ends in !important, it would be splendid if this !important flowed down to all the mixin declarations.
So:
.bordered {
border-top: dotted 1px black;
border-bottom: solid 2px black;
}
#menu a {
color: #111;
.bordered !important;
}
Would generate:
#menu a {
color: #111;
border-top: dotted 1px black !important;
border-bottom: solid 2px black !important;
}
Just to continue the conversation from Issue #100, I would say that specially designating a keyword as having a different mixin behavior is arbitrary and probably not ideal. With using variables, you can append any keyword value as you like into your mixin.
I think of this less as "extending LESS" and more as "making LESS look and act more like CSS", which is one of the appeals of LESS. It's CSS on steroids.
Semantically, if I call .bordered() !important, I'm saying "this declaration is important" and expect it to work just like background-color: #000 !important or whatever.
Having said that, I can see the appeal to allowing non-escaped !important as part of variables, particularly when the mixin might deal with multiple properties and you only want some to be important. I don't think that negates the usefulness of this feature, though.
To respond to your other comment (https://github.com/cloudhead/less.js/issues/100#issuecomment-3375093), yes. For this feature, I would expect a 14-line mixin designated !important to add !important to all 14 lines.
Naturally, as mentioned above, there will be times you may only want some variables to be important, in which case variable-specific !important would be nice, but that's covered by #100. I think there's a use case for both requests.
Damn, you're actually starting to sway me, partly because !important is a special keyword that is available to all CSS declarations. Hmmm..... I guess the next step would be to do a test implementation, and see if @cloudhead wants to pull it into the project. Or maybe ask his thoughts on it first. But I can see your rationale.
Again, though, my caveat. Usually, when I see !important all over CSS, it means that someone probably isn't doing things wisely. BUT one should be free to abuse LESS as much as they abuse CSS. ^_^
Hehe, agreed. It's easy to abuse. This actually came up because of a co-dev's specific need to override some Bootstrap stuff. There were other solutions (he went with an unnecessarily specific selector chain), but in this case !important was the contextually-appropriate solution, and it felt weird not to be able to use it, not least of which was because LESS feels so familiar and so like CSS.
I'll try to dig into the parser and see if I can figure out how to make the change. I'm dumb.
No more dumb than any of the rest of us. The parser stretches my JavaScript brain quite a bit. :-)
I've used Twitter Bootstrap, and have often found the need to override and replace sections. I'd actually love it if subsequent mixins replaced previous mixin definitions. Most of the CSS3 syntax, especially gradients, I've overridden in Bootstrap because I use CSS3Pie for rendering CSS3 in IE, which is much more reliable and flexible than the filter syntax.
Bootstrap is great if you're using as is, but like jQuery Mobile, fails when you really need to customize. It's just not how it's designed.
I like this idea actually, I'll have a look.
ok, it's in! https://github.com/cloudhead/less.js/commit/aab66a4d10e38a4d92c003ecb5ef03b9ff3067cc
.thanks(@cloudhead) !important;
;)
Radness.
Sweet, just came here from google, this is great
.trythis(@iWantIt e("!important"));