Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
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

  • Android Java Project to Merge Multiple PDF Documents From Gallery Using iTextPDF Library
  • Android Java Project to Detect System Hardware & System CPU Info & Display inside TextView Widget
  • Android Java Project to Integrate Google OAuth2 Login & Logout System & Save User Info in SharedPreferences
  • Android Java Project to Export Raw Text to PDF Document Using iTextPDF Library
  • Android Java Project to Export Images From Gallery to PDF Document Using iTextPDF Library
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme