Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS transition shorthand with multiple properties?

I can't seem to find the correct syntax for the CSS transition shorthand with multiple properties. This doesn't do anything:

.element {   -webkit-transition: height .5s, opacity .5s .5s;      -moz-transition: height .5s, opacity .5s .5s;       -ms-transition: height .5s, opacity .5s .5s;           transition: height .5s, opacity .5s .5s;   height: 0;   opacity: 0;   overflow: 0; } .element.show {   height: 200px;   opacity: 1; } 

I add the show class with javascript. The element becomes higher and visible, it just doesn't transition. Testing in latest Chrome, FF and Safari.

What am I doing wrong?

EDIT: Just to be clear, I'm looking for the shorthand version to scale my CSS down. It's bloated enough with all the vendor prefixes. Also expanded the example code.

like image 627
Gregory Bolkenstijn Avatar asked Mar 12 '12 15:03

Gregory Bolkenstijn


People also ask

Which shorthand property is for applying transitions to multiple property values of an element at a time?

The transition CSS property is a shorthand property for transition-property , transition-duration , transition-timing-function , and transition-delay .

Which of the following allows us to transition between one or more property and value to other properties and values?

CSS transitions allows you to change property values smoothly, over a given duration.

Which of the following properties Cannot be used with transition?

It does not show fixed valency.

Are transition properties inherited?

Specifically around properties, like transition properties, that are not inherited by default. Run this demo in my JavaScript Demos project on GitHub. First off, this is not an AngularJS-specific problem (as you might be lead to believe from the post title). This is just a byproduct of CSS behavior.


1 Answers

Syntax:

transition: <property> || <duration> || <timing-function> || <delay> [, ...]; 

Note that the duration must come before the delay, if the latter is specified.

Individual transitions combined in shorthand declarations:

-webkit-transition: height 0.3s ease-out, opacity 0.3s ease 0.5s; -moz-transition: height 0.3s ease-out, opacity 0.3s ease 0.5s; -o-transition: height 0.3s ease-out, opacity 0.3s ease 0.5s; transition: height 0.3s ease-out, opacity 0.3s ease 0.5s; 

Or just transition them all:

-webkit-transition: all 0.3s ease-out; -moz-transition: all 0.3s ease-out; -o-transition: all 0.3s ease-out; transition: all 0.3s ease-out; 

Here is a straightforward example. Here is another one with the delay property.


Edit: previously listed here were the compatibilities and known issues regarding transition. Removed for readability.

Bottom-line: just use it. The nature of this property is non-breaking for all applications and compatibility is now well above 94% globally.

If you still want to be sure, refer to http://caniuse.com/css-transitions

like image 114
20 revs, 5 users 91% Avatar answered Sep 17 '22 17:09

20 revs, 5 users 91%