📜  css coor 背景 - CSS (1)

📅  最后修改于: 2023-12-03 15:30:08.194000             🧑  作者: Mango

CSS Coordinate Background

CSS Coordinate Background is a CSS property that allows you to set a background image that scrolls along with the page's content. It works by defining the starting position of the image in relation to the viewport and then using the background-position property to set the position of the image as the page is scrolled.

Basic Syntax
background-attachment: fixed;
background-position: x-axis y-axis;
background-image: url("image-url");
  • background-attachment: fixed; makes the background image fixed in its position.
  • background-position: x-axis y-axis; sets the position of the background image.
  • background-image: url("image-url"); sets the URL of the background image to be used.
Example
.background {
  background-attachment: fixed;
  background-position: 50% 50%;
  background-image: url("path/to/image.png");
}

This example sets the background image to be fixed in position and centered both horizontally and vertically in the viewport.

Conclusion

CSS Coordinate Background is a useful CSS property that can add depth and visual interest to your web pages. It allows you to create custom backgrounds that move and scroll with the page's content, making for a dynamic user experience.