- To set up a background image, we should set it inside
CSS
file using url(...)
- By default, background image will repeat itself, you can set
background-repeat
to no-repeat
, repeat-x
(only repeat on horizontal axis), or repeat-y
- To strech the image to fit the whole screen, set
background-size
to 100% 100%
, but also need to set height
to 100wh
- You can also strech the image while keeping the aspect ratio by setting
background-size
to cover
- When you scroll the page, to let background image stay still, set
background-attachment: fixed;
body {
body {
/* Provide image url */
background: url(/images/[email protected]);
/* no-repeat for the background img */
background-repeat: no-repeat;
/* let image fit entire screen */
background-size: cover;
/* Push the image 100px left, 100px down */
background-position: 100px 100px;
/* image stay fixed while scolling */
background-attachment: fixed;
}
}