Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mix css3 transform properties without overriding (in realtime)?

Is there any way to combine (mix) css transform properties without overriding? For example there I want to rotate and scale. http://jsfiddle.net/hyzhak/bmyN3/

html

<div class="item rotate-90 tiny-size">     Hello World! </div> 

css

.rotate-90 {     -webkit-transform: rotate(90deg); } .tiny-size {     -webkit-transform: scale(0.25, 0.25); } 

PS

I just have a lot of elements and a lot of simple classes to transform view of the elements. And I just want to tune view of them by adding and removing some classes. Combining of all classes doesn't work because it will be hundreds of combinations.

As well I want to do it in realtime.

The number of transformations can be approximately 5 and each of them can hold about 10 states - so just describe all combinations of them with hands give you approximately

10*10*10*10*10 = 100000 cases 

It is a bad solution.

like image 633
Eugene Krevenets Avatar asked Nov 23 '13 20:11

Eugene Krevenets


People also ask

How can use two transform properties in CSS?

Just start from there that in CSS, if you repeat 2 values or more, always last one gets applied, unless using ! important tag, but at the same time avoid using ! important as much as you can, so in your case that's the problem, so the second transform override the first one in this case...

What does the CSS3 transform property do?

Definition and Usage The transform property applies a 2D or 3D transformation to an element. This property allows you to rotate, scale, move, skew, etc., elements.

Which actions are possible using the CSS3 transforms?

The transform CSS property lets you rotate, scale, skew, or translate an element.

Which CSS property allows block elements to be transformed or changed within two dimensional or three dimensional space?

Abstract. CSS transforms allows elements styled with CSS to be transformed in two-dimensional or three-dimensional space. This spec adds new transform functions and properties for three-dimensional transforms, and convenience functions for simple transforms.


2 Answers

Hmm...as far as I know, you would have to create new class and combine them this way (separated by a space):

-webkit-transform: rotate(90deg) scale(0.25, 0.25); 
like image 187
m59 Avatar answered Sep 26 '22 10:09

m59


The way I get around this issue is to add a wrapper class around the one I want. For example, I have the wrapper which has its position set via javascript, and then the internal which is is affected by css animations - both on the transform property.

I know adding DOM nodes isn't ideal but it circumvents the script-heavy solution and lets the browser optimise the animations and transitions as it would normally.

like image 20
Hugo Scott-Slade Avatar answered Sep 23 '22 10:09

Hugo Scott-Slade