LESS: Using mixins inside mixins misuse of browser prefix - css

SO, here my first mixin
.3transitions (#value1,#value2,#value3,#duration){
#value: ~"#{value1},#{value2},#{value3}";
.transition-property(#value);
.transition-delay(0);
.transition-duration(#duration);
.transition-timing-function(ease);
}
and here is the second (among many others)
.transition-property(#transition-property) {
-webkit-transition-property: #transition-property;
transition-property: #transition-property;
}
On webkit browsers I should get the compiled CSS with proper browser prefix, but I get
-webkit-transition-property: margin-top,opacity,transform;
instead of
-webkit-transition-property: margin-top,opacity,-webkit-transform;
How can I go around this please? Is there a way to determin in LESS that I am using a CSS3 style?

Since Less v2, it become easy to use plugins. The autoprefix plugin post-processed your Less code by autoprefixer.
You can install the autoprefix plugin by running the following command in the console:
npm install -g less-plugin-autoprefix
After installing the plugin you should be able to run for in stance the following command:
echo "element{ transition-property: margin-top,opacity, transform; }" | lessc - --autoprefix="last 20 versions"
The preceding command will compile into CSS code as follows:
element {
-webkit-transition-property: margin-top, opacity, -webkit-transform;
-moz-transition-property: margin-top, opacity, -moz-transform;
-o-transition-property: margin-top, opacity, -o-transform;
transition-property: margin-top, opacity, transform;
}
You can not use this autoprefix plugin when compiling your Less code client side in the browser. For client side in browser compiling you can consider to use -prefixfree This Javascript library add browser’s prefix to any CSS code leveraging Javascript.
When you can not run the autoprefix which requires Node installed, for instance those who compile Less with one of the alternative compilers, you should fall-back to prefix mixins such as that found here written by #seven-phases-max. Better you should not reinvent the wheel and try one of the mixin libraries that already fix the prefix problems for you.

Related

Am I overcomplicating my LESS for vendor prefixes?

I've started using LESS for CSS lately and was wondering if my method is the correct way to target multiple vendor prefixes by creating my own LESS "mixin" (I think)?
.transition (#transition: 1s) {
transition: #transition;
-webkit-transition: #transition;
-moz-transition: #transition;
}
So if I were for example to have a .btn class and call .transition (which works)
.btn:hover {
color: red;
.transition(#transition: 1s ease-in);
}
And for animations.
#animate-fadein: fadeIn 1.7s linear;
.animation (#animation: fadeIn .2s linear) {
animation: #animation;
-webkit-animation: #animation;
-moz-animation: #animation;
-o-animation: #animation;
}
.btn
.btn {
#animation(#animation: fadeIn .2s linear);
}
This method works by the way. I'm just curious. Is my method over-complicating things and or am I just reinventing the wheel?
Well, using mixins help you to code more DRY (Don't repeat yourself), so that's good and the main reason why you should use Less.
When your requirements change ( different browser to support) you will only have to change your mixins (which you can share over your projects too).
Notice that there are many mixin libraries to find on the web which have already create these prefix mixins for you. See: http://lesscss.org/usage/#frameworks-using-less-mixin-libraries
As already mentioned by #seven-phases-max, nowadays most people use autoprefix postprocessors to prefix their mixins. Also Bootstrap have integrate the autoprefixer into their Grunt build process in favor of the prefix mixins (since version 3.2). The only disadvantage of the most popular autoprefix postprocessor (https://github.com/postcss/autoprefixer) will be that it require Node.js installed and can not be used with some alternative compilers.
Since version 2 of Less its easy to use plugins. Less provide you an autoprefix plugin too. This plugin can be installed by running npm install -g less-plugin-autoprefix. After installing you can run for instance lessc --autoprefix="last 2 versions" main.less.
The Less autoprefix plugin an not use when compiling your Less code client side with the less.js compiler. -prefixfree seem to be a reasonable alternative when compiling Client side.
Last note about your vendor prefixes in some situations a [Graceful degradation strategy] (https://www.w3.org/community/webed/wiki/Optimizing_content_for_different_browsers:_the_RIGHT_way#Graceful_degradation) will be better than trying to support even the most old browser with newest technologies.

Why is autofixr for sublime not doing it's full job?

I recently downloaded sublime text 3 along with autoPrefixr. I got node.js and made sure it is in the $PATH. I restarted sublime text, yet when i try to run autoPrefixr, it only adds like 10 lines of code to my 150 lines of css. I know it's not doing it's job because I see nothing about -moz- or -o-. Please help as soon as possible, and thanks in advance.
Look for -webkit- prefixes. The reason you're not seeing very many changes is that, by default, the settings are to support the last two versions of each browser. Recent versions of Firefox and Opera don't require the -moz- and -o- prefixes, respectively, to many CSS items, which is the reason you're not seeing them.
To test earlier versions of Firefox and Opera, first create the following generic CSS:
body {
transition: all 1s ease-out;
}
p {
transform: skewx(10deg) translatex(150px);
}
Then, go to Preferences -> Package Settings -> Autoprefixer -> Settings - User and set its content to the following:
{
"browsers": ["last 2 versions", "> 10%", "ff > 4", "opera > 9"]
}
This adds support for the last two versions of any browser, any version with greater than 10% market share, Firefox versions 4 and above, and Opera versions 9 and above.
Save this content, go back to your test CSS file, and run Autoprefix CSS from the Command Palette. You should now get the following:
body {
-webkit-transition: all 1s ease-out;
-moz-transition: all 1s ease-out;
-o-transition: all 1s ease-out;
transition: all 1s ease-out;
}
p {
-webkit-transform: skewx(10deg) translatex (150px);
-moz-transform: skewx(10deg) translatex (150px);
-o-transform: skewx(10deg) translatex (150px);
transform: skewx(10deg) translatex (150px);
}
For more (brief) details about the settings, check the README.

Stylus mixins that use the native CSS3 mixins?

I'm creating a mixin that will allow me to do prefix free styles for transform: rotate(45deg). The problem is that I have no idea how to do it in proper Stylus syntax. Here's what I have so far:
transform-rotate()
-webkit-transform: rotate(arguments)
-moz-transform: rotate(arguments)
-o-transform: rotate(arguments)
-ms-transform: rotate(arguments)
transform: rotate(arguments)
And then I would like to call it in my .styl sheet using the following:
transform-rotate(45deg)
But when I do that, I get the following error:
Cannot call method 'map' of undefined
I think the problem is that Stylus is trying to treat the native CSS3 rotate() mixin as a custom mixin, and when it tries, it can't find the implementation of rotate(). I'm not entirely sure, but that's my initial thought.
How do I write this out so that it'll compile properly? Any ideas would be greatly appreciated. Thanks in advance.
You don't need parentheses with Stylus, problem solved !
transform-rotate
-webkit-transform rotate arguments
-moz-transform rotate arguments
-o-transform rotate arguments
-ms-transform rotate arguments
transform rotate arguments
And I'd advise you to use Nib, a stylus plug-in that handles browser prefixing : http://visionmedia.github.io/nib/

Recreating MS Windows Phone Tiltin Animation in CSS

I am trying to get the "tilt-in" animation working on a little project of mine using CSS animations. Unfortunately I have not been able to port it from the MS Demo where - doubtlessly all the code is there: http://m.microsoft.com/windowsphone/en-us/demo/default.aspx#home
I'm trying to get the tiles to fade in when the page is loaded, just that part. Once is absolutely fine. I understand that I need to define the vendor keyframes, but my attempts have been so poor that I am not pasting them in my example in jsFiddle:
http://jsfiddle.net/qCQQD/2/
Anyone out there who'll help me out? That would be beyond awesome!
EDIT 1:
a) I'm still trying to get the rotateRight animation running when the page is loaded. I've probably got a hacky version with leftRotate in the .tile class and that removed (and rightRotate added) on pageload.
b) This
.tile:active {
-webkit-transform: scale(0.97);
-moz-transform: scale(0.97);
-o-transform: scale(0.97);
-ms-transform: scale(0.97);
transform: scale(0.97);
}
got super slow in Chrome because of the code added, how can I get it back to normal?
I suspect it takes some sort of timeframe from the #tile
-webkit-transition: 300ms 160ms;
It looks like a slow motion right now. I'm going to try adding something like -webkit-transition: 50ms to it. (yeah I know, total noob).
Basically like this. You have it set up fairly correctly, but you just need to actually change some settings. Check this jsfiddle DEMO out.
I'm only using javascript to add a class or remove a class. You could simply do that sort of stuff on a :hover tag in css also it would do the same thing.
I mainly just modified your css to include a rotate(90deg) -webkit-transition. Therefore this will only work in chrome and probably safari. If you want it to work in firefox then you'll have to do the -moz-transition for the rotation.

Is there a way to create a fade-in/fade-out effect using CSS 3 only?

Is there a way to create a fade-in/fade-out effect on mouse over/out respectively that only uses CSS 3?
If there is, would you say that it is a good way to implement such an effect with CSS only or not?
To me, it seems like a presentation only issue so I'm not sure why JavaScript should be involved?
Are you looking for something like this: http://jsfiddle.net/hRuR9/2/ ?
It's pretty simple...
.box{
opacity: 0.0;
-webkit-transition: 0.5s all;
-moz-transition: 0.5s all;
}
.box:hover{
opacity: 1.0;
}
As for whether using it or not is a good idea, it depends on your target audience and which browsers you expect them to use or want to support. Recent versions of Safari, Chrome, and Firefox (and I believe Opera) support it. No idea about recent versions of IE, but you can pretty much forget about the older ones.

Resources