Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Sitemap
Menu

How to Animate a Background Image in HTML & CSS

Posted on January 12, 2023

 

 

Welcome folks today in this blog post we will be animating background image with cloud moving animation in html and css. All the full source code of the application is shown below.

 

 

Get Started

 

 

In order to get started you need to make an index.html file and copy paste the following code

 

 

index.html

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Page Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" media="screen" href="main.css" />
</head>
<body>
  <div class="centered">Moving clouds background animation.</div>
</body>
</html>

 

 

Now we need to copy paste the css code inside the style.css file as shown below

 

 

style.css

 

 

CSS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
body{
  width:560px;
  height:400px;
  background-color:#BFDFEC;
    background-repeat:repeat-x;
background-image:url("https://i.stack.imgur.com/b7z29.png");
  animation: movement 10s linear infinite;
}
 
@keyframes movement{
  0% {
    background-position:0px 0px;
  }
  100%{
    background-position:560px 0px;
  }
}
 
adiv{
  display:block;
  position:absolute;
  font-size:2rem;
  text-align:center;
  color:white;
  border:1px solid white;
  padding:2rem;
  border-radius:5px;
  margin-left: auto;
  margin-right: auto;
  
}
 
.centered {
  position: absolute;
  top: 30%;
  left: 30%;
  margin-top: -50px;
  margin-left: -100px;
  font-size:2rem;
  text-align:center;
  color:white;
  border:1px solid white;
  padding:2rem;
 
}

 

Recent Posts

  • Build a Fixed Deposit Interest Calculator Using Amount and Time in Browser Using HTML5 & Javascript
  • How to Download Files From URL in Node.js Using Node-Downloader-Helper Library
  • Angular 10 Image Carousel and Video Gallery Lightbox Modal Slider Using ng-image-slider Library
  • React Unsplash Api Photo Search App
  • React Form Validation Using Formik and Yup
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • javascript
  • Koajs
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme