w3resource
HTML exercises

CSS Properties: How to binding an animation to a division element?

Go to Exercise page

Solution:

HTML Code:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>How to binding an animation to a division element</title>
</head>

<body>
<div class="animation">
<div class="w3r">
w3resource Tutorial
</div>
<div class="cylon_eye"></div>
</div>
<style type="text/css">
.w3r {
color: white;
float: left;
margin-right: 2%;
font-size: 20px            
}

.animation {
background-color: #CC3333;
height: 40px;
width: 100%;
overflow: hidden;
}

.cylon_eye {
background-color: #FFCC99;
background-image: -webkit-linear-gradient(    left, rgba( 0,0,0,0.9 ) 25%, rgba( 0,0,0,0.1 ) 50%, rgba( 0,0,0,0.9 ) 75%);
background-image:    -moz-linear-gradient(    left, rgba( 0,0,0,0.9 ) 25%, rgba( 0,0,0,0.1 ) 50%, rgba( 0,0,0,0.9 ) 75%);
background-image:      -o-linear-gradient(    left, rgba( 0,0,0,0.9 ) 25%, rgba( 0,0,0,0.1 ) 50%, rgba( 0,0,0,0.9 ) 75%);
background-image:         linear-gradient(to right, rgba( 0,0,0,0.9 ) 25%, rgba( 0,0,0,0.1 ) 50%, rgba( 0,0,0,0.9 ) 75%);
color: white;
height: 100%;
width: 20%;
-webkit-animation: move_eye 4s linear 0s infinite alternate;
-moz-animation: move_eye 4s linear 0s infinite alternate;
-o-animation: move_eye 4s linear 0s infinite alternate;
animation: move_eye 4s linear 0s infinite alternate;
}
@-webkit-keyframes move_eye { from { margin-left:-20%; } to { margin-left:100%; }  }
@-moz-keyframes move_eye { from { margin-left:-20%; } to { margin-left:100%; }  }
@-o-keyframes move_eye { from { margin-left:-20%; } to { margin-left:100%; }  }
@keyframes move_eye { from { margin-left:-20%; } to { margin-left:100%; }  }
</style>
</body>
</html>

Live Demo:

See the Pen animation-answer by w3resource (@w3resource) on CodePen.


See the solution in the browser

Supported browser

Firefox logo Chrome logo Opera logo Safari logo Internet Explorer logo
Yes Yes Yes Yes No

Go to Exercise page

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming