CSS背景background、background-position使用详解

2020-05-02 08:17:31易采站长站整理

页面已经向下滚动了,但是图像仍然保持可见。

需要重视的一点是背景图只能出现在它父元素能达到的区域。即使图片是相对于视口(view port)定位地,如果它的父元素不可见,图片就会消失。参见下面的例子。此例中,图片位于视口(view port)的左下方,但是只有元素内的图片部分是可见的。

CSS Code复制内容到剪贴板

background-image: url(test-image.jpg);   
background-position: 0 100%;   
background-repeat: no-repeat;   
background-attachment: fixed;  

Part of the image has been cut off because it begins outside of the element.

因为图片开始在元素之外,一部分图片被切除了。 

英文原文:Backgrounds In CSS: Everything You Need To Know

汉化原文:CSS背景全攻略