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/
Related
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
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.
Hey I am new to development so was trying to change background color when we change menu item, I have done that, but want to have some delay in changing of background color.I tried transition property but got no result.Is transition property not applicable to <body>?As I tried to provide 'id' to <body> and apply rule like this
<body id="color">
CSS
#color {
background-color: yellowgreen;
transition: background-color 2s ;
}
I am doing something wrong? What is the way to apply <div> to full page and apply the same rule?
First, when using transitions, you need to add the -webkit for Safari - http://www.w3schools.com/cssref/css3_pr_transition.asp
If you want a transition effect that takes x amount of time, you can exclude the below transition-delay. But if you want your transition to be delayed by, say 2 seconds, then you can add the transition-delay and set it you the amount of seconds you want to delay the transition for.
#color {
background-color: yellowgreen;
-webkit-transition: background-color 2s ease-in; /* Safari */
transition: background-color 2s ease-in;
-webkit-transition-delay: 2s; /* Safari */
transition-delay: 2s;
Here is a list of some timing-functions you can use for transitions - http://www.w3schools.com/cssref/css3_pr_transition-timing-function.asp
Here is a fiddle to show you how the border-color transition takes .5 seconds to start on hover.
This will work only once while CSS being loaded if this id overwrites preceding or default rules. You might not even noticed it.
Once CSS is loaded, it remains in your browsers and nothing will happen anymore.
You may give a try to link your CSS file with a time stamp to force refreshing CSS each time you reload a page. kind of like /myCssFile.css&id=010012014
Actually, the good practise would be to add a class on onload event and set your transition or animation from there.
CSS is not really meant to do this.
Here is a test i made a while ago : http://codepen.io/gcyrillus/pen/rmhAp You may see an animation the very first time your browser will load it.
Mabye This Will Help
This continually changes the background color.
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.
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/