今天偶然看到的,就做出了一些粗略的了解
作用:设置背景图片的附着方式
前提:需要设置background-image属性
值有:
scroll:
The background is fixed relative to the element itself and does not scroll with its contents.
背景相对于元素本身是固定的,不会随着其内容滚动
fixed:
The background is fixed relative to the viewport. Even if an element has a scrolling mechanism, the background doesn't move with the element
背景相对于视图端口是固定的。即使元素有滚动机制,背景也不会随着元素移动
inherit:从父级继承属性
local:背景相对于元素的内容是固定的。如果元素有滚动机制,则带有元素内容的背景滚动,以及背景绘画区域和背景定位区域相对于元素的可滚动区域,而不是相对于它们的边框
由于mdn上的解释以及实例较为精准,我就没必要再写。只是在这儿提前先翻译下
tp:mdn关于background-attachment的描述
资料来源:https://developer.mozilla.org/en-US/docs/Web/CSS/background-attachment