正在回答 回答被采纳积分+1
1回答
好帮手慕星星
2019-08-04 16:44:39
同学你好,
背景图本身就是在固定在容器中的,容器大小为多少,背景图就会显示多少,容器滚动的时候,背景图不跟着滚动,例如:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <!DOCTYPE html> < html > < head > < meta charset = "UTF-8" > < title >Document</ title > < style > div { width: 100px; height: 100px; background: url(img/7.jpg); overflow-y: scroll; } </ style > </ head > < body > < div >imooc imooc imooc imooc imooc imooc imooc imooc</ div > </ body > </ html > |
只不过页面滚动的时候,容器滚动了,背景图在容器中当然会滚动。
background-attachment:fixed;是设置图片相对于页面滚动的时候固定住的。也就是容器滚动,背景图不滚动。
自己可以测试理解下,祝学习愉快!
相似问题
登录后可查看更多问答,登录/注册
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧