Here we are going to create a css text animation using html css only.
Preview:
HTML Code(index.html)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>CSS Text Reveal</title>
</head>
<body>
<h1 class="main">
<span><b>codeitwise</b></span>
<span>A Platform for Coders...</span>
</h1>
</body>
</html>
Css Code(style.css)
*{
box-sizing: border-box;
}
:root{
--bg-color: #D8D8D8;
}
body {
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
width: 100vw;
height: 100vh;
color: #000;
background-color: var(--bg-color);
font-family: monospace;
}
h1{
font-size: 4em;
font-weight: normal;
}
/* title styles */
.main span{
position: relative;
overflow: hidden;
display: block;
}
.main span::after{
content: '';
position: absolute;
top: 0;
right: 0;
width: 100%;
height: 100%;
background: white;
animation: animation1 2s cubic-bezier(.77,0,.18,1) forwards;
transform: translateX(-101%);
}
.main span::before{
content: '';
position: absolute;
top: 0;
right: 0;
width: 100%;
height: 100%;
background: var(--bg-color);
animation: animation2 2s cubic-bezier(.77,0,.18,1) forwards;
transform: translateX(0);
}
.main span:nth-of-type(1)::before,
.main span:nth-of-type(1)::after{
animation-delay: 1s;
}
.main span:nth-of-type(2)::before,
.main span:nth-of-type(2)::after{
animation-delay: 1.5s;
}
@keyframes animation1{
0% {transform: translateX(-100%)}
100% {transform: translateX(101%)}
}
@keyframes animation2{
0% {transform: translateX(0)}
100% {transform: translateX(200%)}
}More like this-
Post a Comment
If you have any doubts, please let me know