So, I recently worked on some private project, and since I am a big fan of CSS, I want to make most of the animations in CSS, not JavaScript.
Today I wanted to create something like this: Text moves from left to right
I think this is possible with CSS Animations. Theoretically, I have a wrapper div with position: relative, fixed width and overflow: hidden. Inside there is a div with the position: absolute and left: 0 and bottom: 0. Now, in some cases, the text is too long for the parent div, and I wanted the text to βfloatβ, although the parent div: in fact the animation div on the left: 0 to the right: 0.
I came across some CSS animations and tried this
@keyframes floatText{ from { left: 0; } to { right: 0; } }
on the child div. And of course, this did not work. Animations like left: 0 left: -100px work, but this does not guarantee that all text will be visible if it is longer than 100px. Is there a good and clean way to do this job? JavaScript, of course, can break this desired functionality. But I wanted to know if there is a way to do this in pure CSS.
Thanks in advance!
EDIT:
To figure out what is on my mind, I created a gif showing what I want to accomplish using CSS animations: Animated
As you can see, we have three of these kinds next to each other, some have a name that fits directly, some others can be too long and need to be animated back and forth, so the user can read it :)!
Thanks again!
EDIT2:
Is there a way to do something like this?
@keyframes floatText{ from { left: 0px; } to { left: (-this.width+parent.width)px; } }
That would be the final solution, I know that this type of coding is not possible in CSS, but maybe with some CSS3 tweets like calc () or something else? Now I have no ideas :(