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