left-right movement.. css only very generic

后端 未结 1 2036
渐次进展
渐次进展 2020-11-27 08:33

I would like to write a generic css animation to move a div right and left, touching the edges of the container .. to be applied in a simple way to any div of which I know n

相关标签:
1条回答
  • 2020-11-27 08:42

    Use transform combined with left or right to avoid adding any fixed value:

    @keyframes destraSinistra {
      0% {
        left: 0;
      }
      100% {
        left: 100%;
        transform:translateX(-100%);
      }
    }
    
    
    #div1 {
      position: absolute;
      border: solid 1px lightgray;
      width: 100px;
      height: 30px;
      background-color: lightgreen;
      animation: destraSinistra 1s linear infinite alternate
    }
    <div id="div1"></div>

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