Step 1
<div id="sky">
<div id="clouds"></div>
</div>
#clouds {
background-image: url('pic.jpg');
background-size: cover;
}
Step 2
overflow: hidden
to the outer div to prevent horizontal scroll bar (since the image div width is twice the screen width).#sky {
overflow: hidden;
}
#clouds {
width: 200%;
height: 400px;
background-image: url('pic.jpg');
background-size: cover;
}
Step 3
@keyframes
rule is used. The idea is to place the left end of the image at margin-left: 0px
at the start of animation and at margin-left: -100%
at the end of animation. As an effect of this, the first half of the image is visible as the animation starts, and the second half of the image is visible as the animation is 100% complete.infinite
to the property animation
. I named the animation 'movingclouds' and the animation duration 25 sec. The more the animation duration, lesser will be the speed of animation.<div id="sky">
<div id="clouds"></div>
</div>
#sky {
overflow: hidden;
}
#clouds {
width: 200%;
height: 400px;
background-image: url('pic.jpg');
background-size: cover;
-webkit-animation: movingclouds 25s linear infinite;
-moz-animation: movingclouds 25s linear infinite;
-o-animation: movingclouds 25s linear infinite;
}
@keyframes movingclouds {
0% {margin-left: 0%;}
100% {margin-left: -100%;}
}