在调整页面大小时如何将背景图像设置在同一个地方

时间:2018-06-01 15:03:35

标签: css background-image

我想在整个页面上设置背景,但是当我调整页面大小时,图像正在改变它的位置。图像高度为3065像素,所以这不是问题。

  .bg {
  background-image: url("#");
  height: 3065px;
  width: 100%; 
  background-position: top center;
  background-repeat: no-repeat;
  background-size: cover;}

1 个答案:

答案 0 :(得分:1)

尝试这个(背景图像的高度和宽度):

bg. {

          /* Location of the image */
  background-image: url(images/background-photo.jpg);

  /* Background image is centered vertically and horizontally at all times */
  background-position: center center;

  /* Background image doesn't tile */
  background-repeat: no-repeat;

  /* Background image is fixed in the viewport so that it doesn't move when 
     the content's height is greater than the image's height */
  background-attachment: fixed;

  /* This is what makes the background image rescale based
     on the container's size */
  background-size: cover;

  /* Set a background color that will be displayed
     while the background image is loading */
  background-color: #464646;

}