<div class="container">
<h1 class="reveal">
<span class="reveal__content">
Reveal Text and Images
</span>
<span class="reveal__artifact"></span>
</h1>
<br />
<p class="reveal">
<span class="reveal__content">
using CSS animations
</span>
<span class="reveal__artifact"></span>
</p>
<br />
<div class="reveal">
<span class="reveal__content">
<img src="//placehold.it/400x300" alt="Image" />
</span>
<span class="reveal__artifact"></span>
</div>
</div>
body {
min-height: 100vh;
margin: 0;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
font: 400 16px/1.5 sans-serif;
}
.container {
padding: 30px;
}
h1 {
margin-top: 0;
margin-bottom: 10px;
}
p {
margin-top: 0;
margin-bottom: 20px;
}
.reveal {
position: relative;
display: inline-block;
white-space: nowrap;
&__artifact,
&__content {
animation-duration: 1s;
animation-delay: 0.5s;
animation-iteration-count: 1;
animation-fill-mode: both;
}
&__artifact {
position: absolute;
top: 0;
left: 0;
width: 0%;
height: 100%;
background-color: red;
animation-name: reveal;
}
&__content {
animation-name: reveal-content;
}
// Delay sequential reveal elements (<br /> counts as a child, hence 1, 3, 5 nth-child's)
&:nth-child(3) {
.reveal__artifact,
.reveal__content {
animation-delay: 1s;
}
}
&:nth-child(5) {
.reveal__artifact,
.reveal__content {
animation-delay: 1.5s;
}
}
}
@keyframes reveal {
0%, 100% {
width: 0%;
left: 0%;
}
50% {
width: 100%;
left: 0%;
}
100% {
left: 100%;
}
}
@keyframes reveal-content {
0%,
49.999% {
opacity: 0;
}
50% {
opacity: 1;
}
}
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.