How to apply multiple transforms in CSS?

前端 未结 7 1563
死守一世寂寞
死守一世寂寞 2020-11-22 06:09

Using CSS, how can I apply more than one transform?

Example: In the following, only the translation is applied, not the rotation.

li:nth         


        
7条回答
  •  我寻月下人不归
    2020-11-22 06:34

    You have to put them on one line like this:

    li:nth-child(2) {
        transform: rotate(15deg) translate(-20px,0px);
    }
    

    When you have multiple transform directives, only the last one will be applied. It's like any other CSS rule.


    Keep in mind multiple transform one line directives are applied from right to left.

    This: transform: scale(1,1.5) rotate(90deg);
    and: transform: rotate(90deg) scale(1,1.5);

    will not produce the same result:

    .orderOne, .orderTwo {
      font-family: sans-serif;
      font-size: 22px;
      color: #000;
      display: inline-block;
    }
    
    .orderOne {
      transform: scale(1, 1.5) rotate(90deg);
    }
    
    .orderTwo {
      transform: rotate(90deg) scale(1, 1.5);
    }
    A
    A

提交回复
热议问题