HTML Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" /><!-- Declare character encoding -->
<title>How to specify the duration of an animation takes to complete</title><!-- Set the title of the HTML document -->
</head>
<body>
<div class="animation"><!-- Container for the animated element -->
<div class="w3r"><!-- Division element for text content -->
w3resource Tutorial
</div>
</div>
<style type="text/css"> /* CSS style start*/
.w3r {
color: white; /* Set text color to white */
float: left; /* Float the element to the left */
margin-right: 2%; /* Set right margin to 2% */
font-size: 20px; /* Set font size to 20 pixels */
}
.animation {
background-color: #CC3333; /* Set background color */
height: 50px; /* Set height */
width: 100%; /* Set width to 100% */
overflow: hidden; /* Hide overflow */
}
div {
width: 100px; /* Set width of the animated element */
height: 100px; /* Set height of the animated element */
background: #33FFFF; /* Set background color */
position: relative; /* Set position property to relative */
-webkit-animation: move 5s infinite; /* Chrome, Safari, Opera */ /* Apply animation to the element for Webkit browsers */
-webkit-animation-delay: 5s; /* Chrome, Safari, Opera */ /* Delay the start of the animation for Webkit browsers */
animation: move 5s infinite; /* Apply animation to the element */
animation-duration: alternate, reverse, normal; /* Set animation duration */
}
/* Chrome, Safari, Opera */
@-webkit-keyframes mymove { /* Define keyframes for the animation in Webkit browsers */
from {top: 0px;} /* Set initial state */
to {top: 200px;} /* Set final state */
}
@keyframes mymove { /* Define keyframes for the animation */
from {top: 0px;} /* Set initial state */
to {top: 200px;} /* Set final state */
}
</style>
</body>
</html>
Explanation:
Live Demo:
See the Pen animation-duration-answer by w3resource (@w3resource) on CodePen.
See the solution in the browser
Supported browser
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4