Combining multiple “transform” entries in Less

旧时模样 提交于 2019-12-03 23:01:13

Provide your transforms as arguments for a single mixin:

.transform(@scale,@rotate) {
  -webkit-transform: @arguments;
}

I guess, you also could achieve to concatenate your separate mixins into one with the help of guards, but I'm not entirely sure;)

I think you are not able to achieve this in another way, since the parser would have to modify code afterwards which should not be possible.

Starting from Less v1.7.0, merging property values with a space separator is possible and there is no need to club the two mixins into one.

The below Less code

.rotate(@deg) {
  -webkit-transform+_: rotate(@deg);
}

.scale(@factor) {
  -webkit-transform+_: scale(@factor);
}

div{
    .rotate(45deg);
    .scale(1.5);
}

will compile into the following CSS:

div {
  -webkit-transform: rotate(45deg) scale(1.5);
}

I think there is a simple way over it, create a div container for the eleemnt, and apply first transform to the cntainer, leaving the second one for the element itself

I was having problems getting @arguments to work. I used the @rest variable which did the trick

LESS example:

.transform(@rest...) {
   transform: @rest;
   -ms-transform: @rest;
   -webkit-transform: @rest;
}

.someClass{
   .transform(translate3D(0,0,0),scale(1,1));
}

.otherClass{
   .transform(translate3D(0,0,0),rotate(1,1));
}

.anotherClass{
   .transform(rotate(1,1));
}

Output CSS:

.someClass {
  transform: translate3D(0, 0, 0) scale(1, 1);
  -ms-transform: translate3D(0, 0, 0) scale(1, 1);
  -webkit-transform: translate3D(0, 0, 0) scale(1, 1);
}
.otherClass {
  transform: translate3D(0, 0, 0) rotate(1, 1);
  -ms-transform: translate3D(0, 0, 0) rotate(1, 1);
  -webkit-transform: translate3D(0, 0, 0) rotate(1, 1);
}
.anotherClass {
  transform: rotate(1, 1);
  -ms-transform: rotate(1, 1);
  -webkit-transform: rotate(1, 1);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!