What is the difference between transition-all and transition in TailwindCSS - html

Tailwind offers multiple utilities for controlling which CSS properties transition, among these properties there are transition and transition-all.
I went and checked the CSS properties for both classes and here they are in the same order.
transition-property: background-color, border-color, color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 150ms;
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 150ms;
What is the difference between both classes and which one should I use for general transitions?

To understand the difference you need to understand an important thing about animatable properties. Some of them trigger layout changes and some of them don't.
A property that trigger a layout change will have an impact on the performance so it's recommended to avoid them as much as possible
A property that doesn't trigger a layout change will have less impact on the performance and it's recommended to animate them.
The transition class of tailwind is grouping the second set of properties (the ones that don't trigger layout change) while transition-all group all of them.
It's better to rely on transition to have good performance and you should avoid as much as possible transition-all but if you are obliged to animate all the properties then use it.
Here is a good reference to help you understand what I am talking about: https://csstriggers.com/
If you check for color you can read:
Changing color does not trigger any geometry changes, which is good.
As a side note, transform is the best when it comes to performance. It doesn't trigger layout change and doesn't trigger painting:
Changing transform does not trigger any geometry changes or painting, which is very good. This means that the operation can likely be carried out by the compositor thread with the help of the GPU.

As you mentioned, Tailwind's transition class defines transitions for a limited set of CSS properties: background-color, border-color, color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter.
When using transition-all all properties that can transition will - this includes all animatable CSS properties (properties in transition and much more).
Using one or the other will depend on which properties you want to animate, if they're all covered by transition then there's no need to use transition-all.

I think If you need all properties its better to use transition-all
but if you want to be specific Use the transition-{properties} utilities to specify which properties should transition when they change.
e.g. transition-color going to be
transition-property: background-color, border-color, color, fill, stroke; as tailwind doc

Related

Transition on position change in css

I would like to add a transition on an element when I am changing its position (from static to fixed).
I tried doing a transition: transition: position 2s linear; but it actually doesn't do anything. Is there anything else I could try ?
Thanks
You're using the declaration properly, however you can only transition numeric values - this is because transition will calculate inbetween steps for the two values you're transitioning between, and while 0% and 100% have steps inbetween, there is no valuefor three-quarters-fixed-one-quarter-static.
The working draft for the transition shorthand has a few pointers on what can reasonably be animated.
In other words, you won't be able to animate this with transition, so the only possible way is likely through JS at this point. With the code you provided, that is impossible to say, though.

Does 'will-change' or the translateZ() hack improve any performance on 'transition: height'

I am building an accordion with animated height on open/close, in which the content height is calculated via JS. I want to ensure the best performance, so I was thinking about forced hardware acceleration.
.accordion-item-content {
overflow: hidden;
transition: height .3s ease;
transform: translateZ(0);
will-change: transform;
}
In the Chrome Dev Tools I can see that the accordion-items are each getting a layer (because of the will-change and/or transform property), but will this result in any performance boost?
Or are transform, opacity and filter the only properties that can ever benefit from GPU rendering, as I understood here: http://www.sitepoint.com/introduction-to-hardware-acceleration-css-animations/
Another question: Does 'will-change: height' do anything? It looks like it's valid (https://developer.mozilla.org/en-US/docs/Web/CSS/will-change), but it does NOT create a layer, I can observe in the dev tools.
Not really will-change or transform: translateZ() will promote your element to it's own layer which get's send over to your GPU.
Have a look at https://csstriggers.com/. You should only animate transform and opacity. Any other properties cause repaint or layout recalculation even if you are using will-change.

Definition of short css transition commands?

I found the following short definition of CSS transition commands, but I don't know what those stand for:
-webkit-transition: all 0.35s ease-in-out 0s;
What does the all stand for?
Why 0s ?
all means that all animatable properties are going to be animated; it's the default, so it can be omitted; of course, you are going to see a transition only for those properties that actually change value between initial and final state;
0s is the transition delay; can be omitted if it's 0s (there may be
issues in some browsers with writing just 0 instead of 0s)
So that code is actually equivalent to:
transition: .35s ease-in-out;
Also, the line you've written uses the -webkit- prefix which means it's only going to work only in WebKit browsers. However, all current versions of desktop browsers that support transitions support them unprefixed.
There are some great articles detailing the use of transition -
http://css-tricks.com/almanac/properties/t/transition/
https://developer.mozilla.org/en-US/docs/Web/CSS/transition
'All' specifies the properties to transition.
The final time parameter is a delay argument. '0s' means, as you'd expect, no delay.
If I wanted to transition just the background colour, and delay by 4 seconds, I would write:
transition: background-color 0.35s ease-in-out 4s;
transition: <property> <duration> <easing> <delay>;
Universal property transition is shorthand for 4 individual properties: transition-property, transition-duration,transition-delay, and transition-timing-function.
First 2 properties are required even though a default value for transition-property is all which defines that all properties that can transition will transition. The transition-timing-function property is defined by predefined functions.
Duration and delay properties are defined with seconds or milliseconds, just keep in mind that first time defined is always duration.
Source: https://kolosek.com/css-transition/

Can I Add a CSS3 Transition to list-images-style?

I want a CSS3 linear transition for a "list-style-image". It will be for Firefox, so it will have "-moz-".
-moz-transition: list-style-image 0.2s linear;
The above code does not work. Is it even possible? Thanks in advance.
No. Transitions generally only work on things where the intermediate steps can be calculated in a predictable way: colors or numbers (in px, em, generally). Images or binary style types (like display none/block) are either one value or the other, and have no intermediate values to use in transition.

Different durations for different properties using WebKit transitions/animation

I'm using WebKit transition to animate certain CSS changes.
For example, say I've got a red box that I want to change to green when someone hovers. I use this:
-webkit-transition-duration: 200ms;
-webkit-transition-property: background;
-webkit-transition-timing-function: ease;
That works great. But now, say I want it to also slide downwards a bit. I use this:
-webkit-transition-property: background, margin;
That also works okay, but I want the box to slide down quickly (say 50ms). I can't change -duration because that would make the color animate fast.
How can I assign different durations to different properties in CSS animations?
I'm fine with using keyframe animations if necessary, but I haven't seen a way that they can help me.
jsfiddle for reference
Duratons can be comma-separated, corresponding to the transitioned properties, ie:
-webkit-transition-duration: 50ms, 200ms;
-webkit-transition-property: margin, background;
http://jsfiddle.net/bQ8d7/1/