HTML과 CSS를 통해 슬라이드 텍스트 애니메이션을 구현해보도록 하겠습니다. 이 프로젝트는 유튜브 DarkCode님의 영상에 있던 프로젝트를 그대로 따라한 것이며, 코드 보관 및 정리를 위해 포스팅합니다.
slidingText.html
0.00MB
slidingText.css
0.00MB
○ slidingText.html 파일의 코드 내용
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="slidingText.css">
</head>
<body>
<div class ="animated-text">
<div class="line">Welcome to Coda</div>
<div class="line">Let's play</div>
<div class="line">programming</div>
<div class="line">with HTML/CSS</div>
</div>
</body>
</html>
○ slidingText.css 파일의 코드 내용
body{
margin: 0;
padding: 0;
font-family: montserrat, sans-serif;
background: black;
}
.animated-text{
color: #fff;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: #2980b9;
padding: 0 40px;
height: 60px;
overflow: hidden;
}
.line{
text-transform: uppercase;
text-align: center;
font-size: 40px;
line-height: 60px;
}
.line:first-child{
animation: anim 12s infinite;
}
@keyframes anim {
0%{
margin-top : 0;
}
16%{
margin-top : -60px;
}
33%{
margin-top : -120px;
}
50%{
margin-top : -180px;
}
66%{
margin-top : -120px;
}
82%{
margin-top : -60px;
}
100%{
margin-top : 0;
}
}