background-attachment 属性 决定背景图像的位置是在视口内固定,或者随着包含它的区块滚动。

  • fixed: 背景图像固定在视口内,即使滚动页面也不会移动。
  • scroll: 背景图像随着包含它的区块滚动。

示例:

body {
  background-image: url('images/background.jpg');
  background-attachment: fixed;
}

解释:

以上代码将设置背景图像为 images/background.jpg,并且使用 background-attachment: fixed; 属性将背景图像固定在视口内。即使滚动页面,背景图像也不会移动。

注意:

background-attachment 属性通常与 background-positionbackground-repeat 属性一起使用,以控制背景图像的显示方式。


原文地址: https://www.cveoy.top/t/topic/nGhS 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录