<!-- Forum question answer only -->
<!-- not a real demo -->
<section class="animation-box">
<span class="text">THIS</span>
<span class="square1"></span>
<span class="text2">THAT</span><br>
</section>
<!-- my version -->
<p class="animate"><span>This</span><span>That</span< /p>
body {
background: #666;
}
.animation-box {
min-height: 4.5rem;
margin: 175px auto 0;
display: flex;
align-items: center;
width: 100%;
overflow: hidden;
}
.animation-box span {
opacity: 1;
animation: leftFadeInOut 18.5s ease 2.75s forwards;
}
.text {
font-size: 30px;
color: #000;
}
.square1 {
width: 1.75vw;
height: 1.75vw;
background-color: #ccc;
margin: auto;
}
.text2 {
font-size: 30px;
color: #fff;
}
/*
@keyframes leftFadeInOut {
0%,
33% {
position: absolute;
left: 1rem;
opacity: 0;
}
75% {
position: absolute;
left: 40rem;
opacity: 1;
}
100% {
position: absolute;
left: 79.5rem;
opacity: 0;
}
}
*/
/* note it would be better to use transform rather than left as transform is more performant. Also avoid the use of magic numbers such as 79.5rem */
/* My version */
.animate {
min-height: 4.5rem;
margin: 75px 0 0;
display: flex;
align-items: center;
animation: slide 18.5s ease 2.75s;
}
.animate span {
font-size: 30px;
color: #000;
text-transform: uppercase;
order: 1;
}
.animate:before {
content: "";
width: 1.75vw;
height: 1.75vw;
background-color: #ccc;
margin: auto;
order: 2;
}
.animate span:last-child {
color: #fff;
order: 3;
}
@keyframes slide {
0% {
width: 0%;
opacity: 0;
}
100% {
width: 100%;
opacity: 1;
}
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.