JSFiddle - React, Tailwind, and code Playground

HTML

<div id="wrapper">
    <div id="innerwrapper">
        <span id="move">Moving element</span>
    </div>
</div>
<p>I want the moving element to reach the very right of the rectangle but not go off of it.</p>

CSS

#wrapper {
    background-color:#aaa;
    display:table;
    width:250px;
    height:100px;
}

#innerwrapper {
    display:table-cell;
    vertical-align:middle;
}

#move {
    position:relative;
    background-color:green;
    -webkit-animation: backandforth 2s ease 0s;
    -webkit-animation-iteration-count:infinite;
    animation: backandforth 2s ease 0s;
    animation-iteration-count:infinite;
}

@-webkit-keyframes backandforth {0%{left:0;} 50%{left:58%;} 100%{left:0;}}

@keyframes backandforth {0%{left:0;} 50%{left:100%;} 100%{left:0;}}