1e41f4b71Sopenharmony_ci# Defining Animations with the background-position Attribute
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ciBy changing the **background-position** attribute (where the first value is the position on the x-axis and the second value is the position on the y-axis), you move a background image. If the background image goes beyond the respective component boundaries, the excess parts will not be displayed.
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci```html
8e41f4b71Sopenharmony_ci<!-- xxx.hml -->
9e41f4b71Sopenharmony_ci<div class="container">
10e41f4b71Sopenharmony_ci  <div class="content"></div>
11e41f4b71Sopenharmony_ci  <div class="content1"></div>
12e41f4b71Sopenharmony_ci</div>
13e41f4b71Sopenharmony_ci```
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci```css
17e41f4b71Sopenharmony_ci/* xxx.css */
18e41f4b71Sopenharmony_ci.container {
19e41f4b71Sopenharmony_ci  height: 100%;
20e41f4b71Sopenharmony_ci  background-color:#F1F3F5;
21e41f4b71Sopenharmony_ci  display: flex;
22e41f4b71Sopenharmony_ci  flex-direction: column;
23e41f4b71Sopenharmony_ci  justify-content: center;
24e41f4b71Sopenharmony_ci  align-items: center;
25e41f4b71Sopenharmony_ci  width: 100%;
26e41f4b71Sopenharmony_ci}
27e41f4b71Sopenharmony_ci.content{
28e41f4b71Sopenharmony_ci  width: 400px;
29e41f4b71Sopenharmony_ci  height: 400px;
30e41f4b71Sopenharmony_ci  /* The aspect ratio 1:1 is not recommended. */
31e41f4b71Sopenharmony_ci  background-image: url('common/images/bg-tv.jpg');
32e41f4b71Sopenharmony_ci  background-size: 100%;
33e41f4b71Sopenharmony_ci  background-repeat: no-repeat;
34e41f4b71Sopenharmony_ci  animation: change 3s infinite;
35e41f4b71Sopenharmony_ci  border: 1px solid black;
36e41f4b71Sopenharmony_ci}
37e41f4b71Sopenharmony_ci.content1{
38e41f4b71Sopenharmony_ci  margin-top:50px;
39e41f4b71Sopenharmony_ci  width: 400px;
40e41f4b71Sopenharmony_ci  height: 400px;
41e41f4b71Sopenharmony_ci  background-image: url('common/images/bg-tv.jpg');
42e41f4b71Sopenharmony_ci  background-size: 50%;
43e41f4b71Sopenharmony_ci  background-repeat: no-repeat;
44e41f4b71Sopenharmony_ci  animation: change1 5s infinite;
45e41f4b71Sopenharmony_ci  border: 1px solid black;
46e41f4b71Sopenharmony_ci}
47e41f4b71Sopenharmony_ci/* Move the background image out of the component. */
48e41f4b71Sopenharmony_ci@keyframes change{
49e41f4b71Sopenharmony_ci  0%{
50e41f4b71Sopenharmony_ci    background-position:0px top;
51e41f4b71Sopenharmony_ci  }
52e41f4b71Sopenharmony_ci  25%{
53e41f4b71Sopenharmony_ci    background-position:400px top;
54e41f4b71Sopenharmony_ci  }
55e41f4b71Sopenharmony_ci  50%{
56e41f4b71Sopenharmony_ci    background-position:0px top;
57e41f4b71Sopenharmony_ci  }
58e41f4b71Sopenharmony_ci  75%{
59e41f4b71Sopenharmony_ci    background-position:0px bottom;
60e41f4b71Sopenharmony_ci  }
61e41f4b71Sopenharmony_ci  100%{
62e41f4b71Sopenharmony_ci    background-position:0px top;
63e41f4b71Sopenharmony_ci  }
64e41f4b71Sopenharmony_ci}
65e41f4b71Sopenharmony_ci/* Move the background image within the component. */
66e41f4b71Sopenharmony_ci@keyframes change1{
67e41f4b71Sopenharmony_ci  0%{
68e41f4b71Sopenharmony_ci    background-position:left top;
69e41f4b71Sopenharmony_ci  }
70e41f4b71Sopenharmony_ci  25%{
71e41f4b71Sopenharmony_ci    background-position:50% 50%;
72e41f4b71Sopenharmony_ci  }
73e41f4b71Sopenharmony_ci  50%{
74e41f4b71Sopenharmony_ci    background-position:right bottom;
75e41f4b71Sopenharmony_ci  }
76e41f4b71Sopenharmony_ci  100%{
77e41f4b71Sopenharmony_ci    background-position:left top;;
78e41f4b71Sopenharmony_ci  }
79e41f4b71Sopenharmony_ci}
80e41f4b71Sopenharmony_ci```
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci> **NOTE**
84e41f4b71Sopenharmony_ci>
85e41f4b71Sopenharmony_ci> The **background-position** attribute can only be used to move background images, but not the background color (**background-color**).
86e41f4b71Sopenharmony_ci>
87e41f4b71Sopenharmony_ci> ![en-us_image_background_img.gif](figures/en-us_image_background_img.gif)
88