How to apply multiple transforms in CSS?

前端 未结 7 1431
死守一世寂寞
死守一世寂寞 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:52

    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...

    So how you can do what you want then?...

    Don't worry, transform accepts multiple values at the same time... So this code below will work:

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

    If you like to play around with transform run the iframe from MDN below:

    Look at the link below for more info:

    << CSS transform >>

提交回复
热议问题