Reputation: 85
trying to do animation. But nothing is happening on Chrome. Normal header is shown.
*{
margin: 0;
height: 0;
box-sizing: border-box;
}
body{
font-family: "Lato", sans-serif;
font-weight: 400;
font-size: 16px;
line-height: 1.7;
color: #777;
padding: 30px;
}
header{
height: 95vh;
background-image: linear-gradient(to right bottom,rgba(126,213,111,0.8), rgba(40,180,131,0.8)),url(../img/hero.jpg);
background-size: cover;
background-position: top;
position: relative;
clip-path: polygon(0 0, 100% 0, 100% 75%, 0 100%);
}
.text-box{
position: absolute;
top: 30%;
left: 50%;
transform: translate(-40%,-50%);
}
.logo-box{
position: absolute;
top: 40px;
left: 40px;
}
.logo{
height: 35px;
}
.heading-primary{
color: #fff;
text-transform: uppercase;
}
.heading-primary-main{
letter-spacing: 35px;
font-weight: 400;
font-size: 60px;
animation-name: moveInLeft;
animation-duration: 4s;
animation-iteration-count: 3;
/*animation-delay: 3s;*/
}
.heading-primary-sub{
display: block;
letter-spacing: 17.5px;
font-weight: 700;
font-size: 20px;
}
@-webkit-keyframes moveInLeft{
0% {
opacity: 0;
transform: translateX(-100px);
}
80%{
transform: translateX(10px);
}
100%{
opacity: 1;
transform: translateX(0);
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css?family=Lato:100,300,400,700,900" rel="stylesheet">
<link rel="stylesheet" href="css/icon-font.css">
<link rel="stylesheet" href="css/style.css">
<link rel="shortcut icon" type="image/png" href="img/favicon.png">
<title>Natours | Exciting tours for adventurous people</title>
</head>
<body>
<header class='header'>
<div class='logo-box'>
<img src='img/logo-white.png' alt='logo' class='logo'>
</div>
<div class='text-box'>
<h1 class="heading-primary">
<span class='heading-primary-main'>Outdoors</span>
<span class='heading-primary-sub'>is where life happens</span>
</h1>
</div>
</header>
</body>
</html>
I want to perform animation such that the heading moves from left to right but nothing is happening as the heading is shown as it is.
I used @-webkit-keyframes
still nothing happened.
Used @keyframes
nothing happened.
Is the problem with the browser(Chrome)?
Please can someone help me?
This animation in CSS i have recently started learning, but this error really demotivate to learn further.
Upvotes: 0
Views: 41
Reputation: 1659
With these changes it works for me perfectly fine -:
.heading-primary {
animation: play 4s steps(10) infinite;
}
@keyframes play {
from {
transform: translate(-100px);
}
to {
transform: translate(0px);
}
}
Upvotes: 1
Reputation: 7661
Instead of transform
you can use margin-left
:
*{
margin: 0;
height: 0;
box-sizing: border-box;
}
body{
font-family: "Lato", sans-serif;
font-weight: 400;
font-size: 16px;
line-height: 1.7;
color: #777;
padding: 30px;
}
header{
height: 95vh;
background-image: linear-gradient(to right bottom,rgba(126,213,111,0.8), rgba(40,180,131,0.8)),url(../img/hero.jpg);
background-size: cover;
background-position: top;
position: relative;
clip-path: polygon(0 0, 100% 0, 100% 75%, 0 100%);
}
.text-box{
position: absolute;
top: 30%;
left: 50%;
transform: translate(-40%,-50%);
}
.logo-box{
position: absolute;
top: 40px;
left: 40px;
}
.logo{
height: 35px;
}
.heading-primary{
color: #fff;
text-transform: uppercase;
}
.heading-primary-main{
letter-spacing: 35px;
font-weight: 400;
font-size: 60px;
animation-name: moveInLeft;
animation-duration: 4s;
animation-iteration-count: 3;
/*animation-delay: 3s;*/
}
.heading-primary-sub{
display: block;
letter-spacing: 17.5px;
font-weight: 700;
font-size: 20px;
}
@-webkit-keyframes moveInLeft{
0% {
opacity: 0;
margin-left: -100%;
}
100%{
opacity: 1;
margin-left: 0;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css?family=Lato:100,300,400,700,900" rel="stylesheet">
<link rel="stylesheet" href="css/icon-font.css">
<link rel="stylesheet" href="css/style.css">
<link rel="shortcut icon" type="image/png" href="img/favicon.png">
<title>Natours | Exciting tours for adventurous people</title>
</head>
<body>
<header class='header'>
<div class='logo-box'>
<img src='img/logo-white.png' alt='logo' class='logo'>
</div>
<div class='text-box'>
<h1 class="heading-primary">
<span class='heading-primary-main'>Outdoors</span>
<span class='heading-primary-sub'>is where life happens</span>
</h1>
</div>
</header>
</body>
</html>
Upvotes: 0