CSS Animation from right to left dynamically

后端 未结 1 848
后悔当初
后悔当初 2021-01-22 20:26

The problem I\'m facing is:

  • I have a animated text which goes from right to left, this text change depending on the languague set, what is causing that the total w
1条回答
  •  北荒
    北荒 (楼主)
    2021-01-22 20:45

    You need a combination of positioning with right and a transform.

    This is an usual idea for centering an element, adapted to your request:

    .container {
      width: 300px;
      background-color: lime;
      margin: 10px;
      position: relative;
    }
    
    .item {
      display: inline-block;
      position: relative;
      right: -100%;
      transform: translateX(-100%);
      transition: right 1s, transform 1s;
    }
    
    .container:hover .item {
      right: 0%;
      transform: translateX(0%);
    }
    Item
    Item long
    Item longer longer

    0 讨论(0)
提交回复
热议问题