Is it possible to combine translateX/translateY and scale in single CSS transition?

柔情痞子 提交于 2019-12-06 15:30:50
  1. In CSS, #id selectors take precedence over .class selectors. Therefore, the transform declarations in your .state classes never get applied. The solution is to either:

    • increase the specificity of your rule, i.e. #circle.stateTwo,

    • add the !important flag to your declaration:

      transform: scale(2, 2) translate(-50%, -50%) !important;
      

      However this should be avoided and the first method used whenever possible.

  2. An easier method to center elements, that doesn't mix with your animation, is to use flexbox:

    .flex-container {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 100vw;
      height: 100vh;
    }
    
    #circle {
      width: 10%;
      padding-top: 10%;
      border-radius: 50%;
      transition: all 1s;
    }
    
    .stateOne {
      background: #800080;
      transform: scale(1.0001, 1.0001);
    }
    
    .stateTwo {
      background: #ffe6ff;
      transform: scale(2, 2);
    }
    
    .stateThree {
      background: #ffe6ff;
      transform: scale(2.0001, 2.0001);
    }
    
    .stateFour {
      background: #800080;
      transform: scale(1, 1);
    }
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!