尝试制作动画。但是Chrome上没有任何反应。显示普通标题。
*{
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>
我想执行动画以使标题从左向右移动,但是按原样显示标题时没有任何反应。
我使用@-webkit-keyframes
仍然没有任何反应。
使用@keyframes
没有任何反应。
浏览器(Chrome)是否有问题?
有人可以帮我吗?
我最近开始学习CSS中的动画,但是这种错误确实无助于进一步学习。
答案 0 :(得分:2)
有了这些更改,它对我来说非常好-:
.heading-primary {
animation: play 4s steps(10) infinite;
}
@keyframes play {
from {
transform: translate(-100px);
}
to {
transform: translate(0px);
}
}
答案 1 :(得分:0)
您可以使用transform
代替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>